decodeErc20Deposit
Decodes the payload of an input added by the ERC-20 portal (depositERC20Tokens).
Portal deposit payloads are packed-encoded (abi.encodePacked) by the rollups contracts InputEncoding library, with layout token (20 bytes) ‖ sender (20 bytes) ‖ value (32 bytes) ‖ execLayerData. There is no function selector, so make sure the input's msgSender is the ERC-20 portal before decoding its payload.
Usage
import { , } from "@cartesi/codec";
const = ("0x...");
const = (.);
// {
// token: "0x...",
// sender: "0x...",
// value: 1000000000000000000n,
// execLayerData: "0xdeadbeef",
// }Parameters
payload(Hex | Uint8Array): packed-encoded deposit payload (thepayloadfield of a decoded input).
Return Type
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.
Addresses are returned checksummed.
Byte fields follow the representation of the encoded data: hex string in, hex string out; byte array in, byte array out. When decoding from a Uint8Array, the returned byte fields are zero-copy subarrays of the input — no data is copied.
Errors
Throws an Error if the payload is shorter than 72 bytes.