The main content of this section is the introduction of encoding and decoding of the parameters passed when calling smart contracts in the Tron network.

When calling smart contracts through the HTTPS triggersmartcontract interface, it is necessary to pass the encoded parameter. Here we use the USDT contract as an example to provide JavaScript code to show developers how to encode the parameters. For details about parameter encoding and decoding in solidity, please refer to [solidity document ](🔗)and [tronweb related code] (

# Parameter encoding

** We take the transfer function in USDT contract as an example: **

Suppose you transfer 50000 USDT to the address 412ed5dd8a98aea00ae32517742ea5289761b2710e, and call the triggersmartcontract interface as follows:

In the above command, the parameter encoding needs to be in accordance with the [ABI rules] 8D # id7), the rules are more complicated, users can use the ethers library to encode, the following is the sample code:

Sample code output:

# Parameter decoding

In the above section of the **_ parameter encoding _**, the invoked triggersmartcontract generates a transaction object, and then signs the broadcast. After the transaction is successfully chained, the transaction information on the chain can be obtained through gettransactionbyid:

The results are as follows:

The raw_data.contract [0] field in the above return value is the parameter that calls the transfer (address to, uint256 value) function, but the data field and the encoding of the **_ parameters are described in the triggersmartcontract described in the section _** The parameter field is not the same. There are 4 abytes of a9059cbb in front. These 4 bytes are the method ID. This is derived from the first 4 bytes of the Keccak hash signed by transfer (address, uint256) in ASCII format. Used by virtual machines to address functions.

The following code decodes the data field to get the parameters passed by the transfer function:

Sample code output:

Note that the third parameter ignoreMethodHash of the decodeParams function must be set to true, so that the decodeParams function skips the first 4 bytes and decodes the subsequent content.

# Return value parameter decoding

** We take the query function in USDT contract as an example: **

Suppose you query the balance of 410583A68A3BCD86C25AB1BEE482BAC04A216B0261 and call the triggersmartcontract interface as follows:

The results are as follows:

The constant_result in the above return value is the return value of balanceOf. Here is the sample code for decoding constant_result:

Sample code output: