3

I am using ethereumjs-accounts providerfor transaction signer in HookedWeb3Provider. And I am trying to call contract function which send tokens. It's my params for sign transaction.

let tx_params = {
        nonce: '00',
        gasPrice: '100',
        gasLimit: '100',
        from: account,
        to: contractParams.address,
        value: '00',
        data: '' //what should I place here to call contract function with arguments?
    };

then I am calling sign method:

signTransaction(tx_params, (err, hash)=>{})

and receiving hash

0xf86280820100832fefd894efcc9f9a5cb3d6062c18eeffdf90a29bb771fccc80801ba07c0226eb53fc4c8031a5346389fb17125b37ca96bec2ce5dd651808c8356ea9aa0aef5cb9e2a0426a6af2193a0fd9d3ec09f334614594faa54be17d9ddd64b72b1

A didn't understand how to send transaction with web3js and put there a signed transaction (or hash?)

this.web3.eth.sendRawTransaction(); 
  • Using github.com/ethereum/wiki/wiki/JavaScript-API#web3ethcontract and contract methods will be simpler and you won't have to manually create the data. Otherwise for the data value you have to use the ABI, compute the Method ID and encode the arguments. – eth Apr 28 '17 at 7:12
  • Thank you. In this case I don't understand how to get sign Object. Agter signTransaction method call I am receiving hash string, but not object.. – Baga Apr 28 '17 at 7:37
  • @eth For function with address, address, value and description - getting code should be like this?: contractInstance.sendFunds.getData('0x7a16108bc3c2751a5a54ca077d4d01aa43ee5c34', '0xdd7b798cbfe06af77fdc4b64e48f71672595adcf', 1, 'hello'); – Baga Apr 28 '17 at 7:54
  • 1
    @eth and one more stupid question. How to get a proof that transaction have been signed? And then how to pass this result do web3.eth.sendRawTransaction? – Baga Apr 28 '17 at 8:10
1

In web3js Version 1.0.0

The data here should be the encoded ABI of the contract method you are trying to execute. See how to encode ABI definition of your contract method here.

For example: If your method call is buyItem('Pasta')

Then you would do something like this

var encodedABI = contractInstance.methods.buyItem(web3.utils.asciiToHex('Pasta')).encodeABI();
  var tx = {
    from: defaultAddress,
    to: contractInstance.options.address,
    gas: 2000000,
    data: encodedABI,
  };

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.