I have a simple contract to set and get a uint256 variable:

contract testContract {

   uint256 test;

   function testContract() {    

   function getTest() constant returns (uint256) {
       return test;    

   function setTest(uint256 _test) {
       test = _test;    

On geth, I update the test variable by

myContract.setTest.sendTransaction(0x12345678901234567890,{from: web3.eth.accounts[0]});

Now to read the variable by

var cardPK = myContract.getTest.call();
console.log("test: " + cardPK.toString(16));

And I obtained

test: 12345678901233c56f80

Why is it wrong?


The correct way to send a big number to contract is by doing :

myContract.setTest.sendTransaction(web3.toBigNumber('0x12345678901234567890'),{from: web3.eth.accounts[0]});
  • Happy you find it out, please accept your own answer later. – Badr Bellaj Aug 17 '17 at 7:46

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.