0

I've a contract, more complex than the following but the concept is the same

pragma solidity ^0.4.23;

contract SimpleCatalog{
    bytes32[] internal x;

    constructor () public{
      x.push(0xa);
      x.push(0xb);
      x.push(0xc);
    }

    function getX() external view returns (bytes32[]){
      return x;
    }
}

When I execute the function in Remix, it returns all the values that I expect that are:

0: bytes32[]: 
0x000000000000000000000000000000000000000000000000000000000000000a,
0x000000000000000000000000000000000000000000000000000000000000000b,
0x000000000000000000000000000000000000000000000000000000000000000c

But if I invoke it with Web3JS, that is:

const web3 = new Web3(window.web3.currentProvider);
console.log(web3.version) //0.19.0
const catalog = 
  (web3.eth.contract(props.catalog.abi)).at(props.catalog.address);
catalog.getX(res => {console.log(res)})

the console prints null. I really don't see the point! Why the function works on Remix and not on Web3JS?

1

The callback parameters are: (error, result). In order to see the expected values from Web3, last line have to be changed i

catalog.getX((err,res) => {console.log(res)})

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.