ethereumjs / ethereumjs-tx

Project is in active development and has been moved to the EthereumJS VM monorepo.
https://github.com/ethereumjs/ethereumjs-vm/tree/master/packages/tx
Mozilla Public License 2.0
779 stars 235 forks source link

How to create txparams.data ? #194

Closed realtebo closed 4 years ago

realtebo commented 4 years ago

Your examnple

const txParams = {
  nonce: '0x00',
  gasPrice: '0x09184e72a000',
  gasLimit: '0x2710',
  to: '0x0000000000000000000000000000000000000000',
  value: '0x00',
  data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057',
}

How to create data having contract abi and params value!?

alcuadrado commented 4 years ago

Hi @realtebo,

You need to encode your function call according to Ethereum's ABI. You can use this library for this: https://github.com/ethereumjs/ethereumjs-abi

You should probably web3.js or ethers.js, as they are higher level libraries than this one.

I'm closing this issue. Feel free to comment if you have other doubts.

realtebo commented 4 years ago

Thanks.

Googling I found a LOT easier solution... I found encodeABI() function in the web3js official library