jeudi 2 mai 2019

How to read public variable in solidity with truffle test codes?

I try to get a value from my public variable in solidity with truffle console, but I don't know the correct syntax.

truffle version Truffle v5.0.14 (core: 5.0.14) Solidity - 0.5.4 (solc-js) Node v11.10.1 Web3.js v1.0.0-beta.37

Here's what I've already tried.

  1. I installed truffle with below command.
    $ npm install truffle -g
    $ truffle init
    $ truffle develop

  1. I have contract named ProxyContract and I set up the 2_deploy_migration.js
    const ProxyContract = artifacts.require("./ProxyContract.sol");

    module.exports = function(deployer) {
        deployer.deploy(ProxyContract).then( () => console.log("ProxyContract: " + ProxyContract.address))
    }

  1. migrated contract.
    truffle(develop)> migrate

  1. When I typed ProxyContract to prompt I could see some object's piece of information and It looked like fine.

  2. and I tried to access 'committeeStatus' variable like this but it just occurred some error codes, even there's no parameter for the 'committeeStatus'

    truffle(develop)> var proxyContract = await ProxyContract.deployed()
    undefined

    truffle(develop)> proxyContract.committeeStatus.call().then(function (res) {console.log(res)})
    Thrown:
    Error: Invalid number of parameters for "committeeStatus". Got 0 expected 1!
        at processTicksAndRejections (internal/process/next_tick.js:81:5)
        at Promise (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-contract/lib/execute.js:128:1)
        at Object._createTxObject (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3-eth-contract/src/index.js:699:1)
        at Object.InvalidNumberOfParams (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3-eth-contract/~/web3-core-helpers/src/errors.js:32:1)

How to get a public variable value via truffle test codes?

Aucun commentaire:

Enregistrer un commentaire