Skip to content
Logo

decodeErc1155SingleDeposit

Decodes the payload of an input added by the ERC-1155 single portal (depositSingleERC1155Token).

Portal deposit payloads are packed-encoded (abi.encodePacked) by the rollups contracts InputEncoding library, with layout token (20 bytes) ‖ sender (20 bytes) ‖ tokenId (32 bytes) ‖ value (32 bytes) ‖ abi.encode(baseLayerData, execLayerData). There is no function selector, so make sure the input's msgSender is the ERC-1155 single portal before decoding its payload.

Usage

import { ,  } from "@cartesi/codec";
 
const  = ("0x...");
const  = (.);
// {
//   token: "0x...",
//   sender: "0x...",
//   tokenId: 42n,
//   value: 7n,
//   baseLayerData: "0x",
//   execLayerData: "0xdeadbeef",
// }

Parameters

  • payload (Hex | Uint8Array): packed-encoded deposit payload (the payload field of a decoded input).

Return Type

A Erc1155SingleDeposit object:

  • token (Address): token contract.
  • sender (Address): token sender.
  • tokenId (bigint): identifier of the token being transferred.
  • value (bigint): transfer amount.
  • baseLayerData (Hex | Uint8Array): additional data to be interpreted by the base layer.
  • 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 104 bytes, or a viem decoding error if the data tail is malformed.