0

I'm using truffle and running locally with 4 quorum nodes, trying to call another contract's function, but keep getting 0 in return instead of the expected value the I get once calling the contract directly.

Truffle v4.1.15

Solidity v0.4.25

Here are the contracts:

contract Token {
   using SafeMath for uint;
   uint _totalSupply;
   address owner;
   mapping(address => uint) balances;

   event Transfer(address indexed from, address indexed to, uint tokens);

   constructor() public {
       _totalSupply = 1000000 * 10**uint(18);
       owner = msg.sender;
       balances[owner] = _totalSupply;
       emit Transfer(address(0), owner, _totalSupply);
   }

   function totalSupply() public view returns (uint) {
       return _totalSupply.sub(balances[address(0)]);
   }
}

contract Marketplace {

   Token public cashToken;

   constructor(address cashTokenAddress) public {
       cashToken = Token(cashTokenAddress);
   }

   function getTotalSupply() public view returns (uint) {
       return cashToken.totalSupply();
   }
}

and here's truffle's 2_deploy_contracts.js:

var SafeMath = artifacts.require("SafeMath");
var Token = artifacts.require("Token");
var Marketplace = artifacts.require("Marketplace");

var account1key = ...
var account2key = ...
var account3key = ...

var publicKeys = [account1key, account2key, account3key];
var tokenAddress;

module.exports = function(deployer) {

 deployer.then(async () => {

   deployer.deploy(SafeMath, {privateFor: publicKeys});
   deployer.link(SafeMath, Token);

   await deployer.deploy(Token, {privateFor: publicKeys}).then(() => {
     console.log("tokenAddress: ", Token.address)
     tokenAddress = Token.address;
   });

   await deployer.deploy(Marketplace, tokenAddress, {privateFor: publicKeys});
 })

};

The response I get while connected to the same node the contracts were deployed from:

truffle(development)> Token.deployed().then(function(contract) { return contract.totalSupply() });
BigNumber { s: 1, e: 24, c: [ 10000000000 ] }

truffle(development)> Marketplace.deployed().then(function(contract) { return contract.getTotalSupply() });
BigNumber { s: 1, e: 0, c: [ 0 ] }

What am I doing wrong?

Many thanks

  • Could you share your genesis? – fixanoid Mar 11 at 15:50
  • here's genesis.json: { "alloc": {}, "coinbase": "0x0000000000000000000000000000000000000000", "config": { "homesteadBlock": 0, "chainId": 1, "eip155Block": null, "eip158Block": null, "isQuorum": true }, "difficulty": "0x0", "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", "gasLimit": "0xE0000000", "mixhash": "0x00000000000000000000000000000000000000647572616c65787365646c6578", "nonce": "0x0", "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "timestamp": "0x00" } – drws Mar 12 at 8:17
  • Hey, so most likely the issues is due to the config. Please add this line to the config section: "byzantiumBlock": 0 – fixanoid Mar 12 at 17:28
  • 1
    I tried adding that to the config but unfortunately it didn't help. Instead, I ended up switching to the updated quorum version on github and now it works. Thanks for the help! – drws Mar 13 at 13:25

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.