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


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

  • 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
    Commented Apr 28, 2017 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
    Commented Apr 28, 2017 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
    Commented Apr 28, 2017 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
    Commented Apr 28, 2017 at 8:10

2 Answers 2


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,

With ethers.js v5:

  1. create your smart contract instance

    const instance = new Contract(address, abi, signerOrProvider)

or just the interface

const interface = new ethers.utils.Interface(abi)

  1. encode data

    const data = instance.interface.encodeFunctionData('yourFuncName', [inputParams])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.