4

I was trying to invoke some function which takes two uint256 numbers as inputs. Something likes this (solidity code)

function doSomething(uint256 input1, 
                     uint256 input2)

I have tried several combinations but still doesn't find a correct way to parse the uint256 parameters to invoke doSomething correctly. For example, the below approach does not work (I tried it in Mix).

input1 = '0xfc9e0eefe9f3a5101b7c025b217c03c95dbf9bb4f2d1d46db238e305af104103';
input2 = '0xabcbcbcbcbbc';
contracts['Sample'].contract.doSomething(input1, input2)

Mix shows input1 as some negative value. The same log if I use the number in decimal format. I wonder whats the correct way of parsing uint256 parameters to a function call from web3.js?

3
input1 = web3.toBigNumber('0xfc9e0eefe9f3a5101b7c025b217c03c95dbf9bb4f2d1d46db238e305af104103');
input2 = web3.toBigNumber('0xabcbcbcbcbbc');
contracts['Sample'].contract.doSomething.call(input1, input2)
  • My Mix still shows input1: -1529986465583978706007266560814094031707524982871219339497837241756090875645. Does it work in yours? – Loi.Luu Jun 9 '16 at 9:38
  • 1
    a forgot the ".call" part of your doSomething ... note that this will call it only on your node and not mine it in to the blockchain, you need to use transactions for that. – Roland Kofler Jun 9 '16 at 9:55
0
let id ='80084422859880547211683076133703299733277748156566366325829078699459944778998';
let uint256Id = web3.eth.abi.encodeParameter('uint256',id)

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.