0

I have a React component within which a web3js function queries numbers from Ethereum by using getNumber() function.

I want to call another function called setNumber() that takes one uint256, by passing to it the output that I'm getting from getNumber(). What would be the best way to do that in Truffle/React?

0

this is the best way for it : consider your contract name is contract and then

first you must get your accounts from web3 lib :

let accounts = await web3.eth.getAccounts()

for setting a number use : await contract.methods.setNumber('your number').send({from : accounts[0]})

and for get a number use : let number = contract.methods.getNumber().call()

| improve this answer | |
  • Thank you for the answer! But how to put the output from getNumber() to setNumber()? – Ruham Mar 8 '18 at 15:00
  • 1
    simple like this : let number = contract.methods.getNumber().call() and after that await contract.methods.setNumber(number).send({from : accounts[0]}) – shahabvshahabi Mar 8 '18 at 15:43

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.