Web3.js – Is Transaction Data the Same as Transaction Input in Web3.js?

transactionsweb3js

The Ethereum RPC API documentation accepts a data field when requesting to sendTransaction.

enter image description here

I notice that when I retrieve a historical transaction from the blockchain, I get back an input field and no data field, such as when using the web3 getTransaction function.

Are the data and input fields equivalent, or are there any differences?

Best Answer

It's the same thing.

When you're going to send a transaction, the data is the combination of: method, parameters which are defined in the ABI, and they're encoded.

data: tokenContract.methods.setPoints(user, point).encodeABI()

When you decode the input data then you'll see something like:

{
  "method": "addLiquidity",
  "types": [
    "address",
    "address",
    "uint256",
    "uint256",
    "uint256",
    "uint256",
    "address",
    "uint256"
  ],
  "inputs": [
    "f45b409a2b978ec02Bb6084e6Acc42867a78Ee9c",
    "326C977E6efc84E512bB9C30f76E30c160eD06FB",
    {
      "type": "BigNumber",
      "hex": "0x043c33c1937564800000"
    },
    {
      "type": "BigNumber",
      "hex": "0x038d7ea4c68000"
    },
    {
      "type": "BigNumber",
      "hex": "0x01"
    },
    {
      "type": "BigNumber",
      "hex": "0x01"
    },
    "f39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
    {
      "type": "BigNumber",
      "hex": "0x61fcafda"
    }
  ],
  "names": [
    "tokenA",
    "tokenB",
    "amountADesired",
    "amountBDesired",
    "amountAMin",
    "amountBMin",
    "to",
    "deadline"
  ]
}

This is created by the encodeABI() function. There's an online lab to check for the input. You can use it to check the input data. Given we can decode it manually, but it faster to use tool.

Related Topic