question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't get value from deployed contract

See original GitHub issue
  • I’ve asked for help in the Truffle Gitter before filing this issue.

Issue

I’m trying to use truffle on Quorum, so I followed tutorial - Building dapps for Quorum: Private Enterprise Blockchains

Steps to Reproduce

  1. unlike tutorial using vagrant, I use docker to build 4 nodes, but I also port forward them to 22000~22003
  2. truffle init
  3. edit truffle-config.js
networks: {
     development: {
      host: "127.0.0.1",     // Localhost (default: none)
      port: 22000,
      network_id: "*",       // Any network (default: none)
      gasPrice: 0,
      gas: 4500000,
      type: "quorum"
     },
}
  1. create contract/SimpleStorage.sol and change required solc to ^0.5.16, then command truffle compile
  2. create migrations/2_deploye_simplestorage.js and modify privateFor parameter
var SimpleStorage = artifacts.require("SimpleStorage");

module.exports = function(deployer) {
  // Pass 42 to the contract as the first constructor parameter
  deployer.deploy(SimpleStorage, 42, {privateFor: ["QE/RfPZh4yom6qPZOk8gfFLMeePGE+F+uG4532VinUs="]})
};
  1. unlock account: geth attach --exec "personal.unlockAccount(eth.accounts[0], '', 60)" http://127.0.0.1:22000
  2. deploy contract: truffle migrate

Expected Behavior

According to tutorial, I should be able to get value from contract once my truffle migrate done

truffle console
truffle(development)> SimpleStorage.deployed().then(function(instance) { return instance.get(); })
{ [String: '42'] s: 1, e: 1, c: [ 42 ] }

Actual Results

truffle console
truffle(development)> SimpleStorage.deployed().then(function(instance) { return instance.get(); })
BN { negative: 0, words: [ 0, <1 empty item> ], length: 1, red: null }

Environment

  • Operating System: Ubuntu 16.04.6 LTS
  • Ethereum client: 1.8.27-stable ( host ) / 1.8.18-stable + Quorum 2.4.0 ( container )
  • Truffle version (truffle version): v5.1.9
  • node version (node --version): v13.6.0
  • npm version (npm --version): 6.13.4

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
gnidancommented, Jan 22, 2020

Hey @yxguo2536, could you throw an extra .then onto the end to convert to string?

truffle(development)> SimpleStorage.deployed().then(function(instance) { return instance.get(); }).then(function(bn) { return bn.toString() });

The first thing to notice is that the tutorial is probably out of date. Your expected result is a BigNumber, but Truffle now uses the BN library instead. If you convert to a string, you’ll see if you get "42" or not.

Let us know! Thanks!

0reactions
eggplantzzzcommented, Mar 31, 2022

Sorry about that @yxguo2536. We’ll close this for issue maintenance for now, if you re-encounter this and can re-report it we would appreciate it!

Read more comments on GitHub >

github_iconTop Results From Across the Web

solidity - Calling function from deployed contract
I have seen a function as follows. function transfer(address _to, uint _value, bytes _data, string _custom_fallback) returns (bool success) { ContractReceiver ...
Read more >
Can't get value from deployed contract · Issue #5130 - GitHub
According to tutorial, I should be able to get value from contract once my truffle migrate done- `` truffle console
Read more >
Can't pass value during the contract deployment in Remix
To fix this I would deploy the contract without any value argument, then create a new function so the owner can set the...
Read more >
How to call another smart contract from your solidity code
1. Smart contracts are the most popular feature of the Ethereum network. Smart contracts have functions ... 2. Smart contracts are computer code,...
Read more >
Interactions between Smart Contracts with Solidity - zupzup
A deployed contract always resides at an address and this address -object in ... to receive return values from the delegated call due...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found