0

it's very tricky, when in the truffle , I call f(),it can't push an item into addressArray.(console.log(addressArray[0]) always unidifined))
but when I use Remix, it worked.

pragma solidity ^0.6.6;

    contract Test{
        address[] public addressArray;
    
        function f() public {
            addressArray.push(msg.sender);
        }
    }
4
  • How are you calling f()? How are you accessing addressArray? It should be possible. To access addressArray from the truffle's console you should do something like console.log(await testContract.addressArray(0)), since it is a getter function.
    – Ismael
    Jan 22 at 17:55
  • thank you, It worked when I use testContract.addressArray(0) instead of testContract.addressArray[0]; :0
    – JESSE Bin
    Jan 23 at 0:28
  • but another question is how can I get this length of the array? when I use console.log(await testContract.addressArray.length) it's undifined
    – JESSE Bin
    Jan 23 at 0:30
  • If you have a new question you should search the site is someone has already asked or create a new one. To get the length you have to add a getter function to the contract.
    – Ismael
    Jan 23 at 5:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.