Skip to content
Logo

encodeErc20Deposit

Encodes an ERC-20 deposit payload as the ERC-20 portal does. This is the inverse of decodeErc20Deposit, useful for testing.

Usage

import {  } from "@cartesi/codec";
 
const  = ({
  : "0x67742ff5b2b762503ff0a92738c6fc2ea4a4d182",
  : "0x92cc14432c1f82622493abd64d99ea8a3000a7c7",
  : 1000000000000000000n,
  : "0xdeadbeef",
});
// "0x67742ff5b2b762503ff0a92738c6fc2ea4a4d18292cc...deadbeef"

Parameters

An Erc20Deposit object:

  • token (Address): token contract.
  • sender (Address): token sender.
  • value (bigint): amount of tokens being sent.
  • execLayerData (Hex | Uint8Array): additional data to be interpreted by the execution layer.

And an optional second parameter:

  • to ("hex" | "bytes", optional): representation of the encoded data. Defaults to "hex".

Return Type

Hex | Uint8Array: packed-encoded deposit payload, with layout token (20 bytes) ‖ sender (20 bytes) ‖ value (32 bytes) ‖ execLayerData.

Returns a Hex string by default, or a Uint8Array when to is "bytes".