[Ethereum] Parse uint256 parameters to a function call from web3.js

mixsolidityweb3js

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?

Best Answer

input1 = web3.toBigNumber('0xfc9e0eefe9f3a5101b7c025b217c03c95dbf9bb4f2d1d46db238e305af104103');
input2 = web3.toBigNumber('0xabcbcbcbcbbc');
contracts['Sample'].contract.doSomething.call(input1, input2)
Related Topic