Skip to content
Logo

decodeErc721Deposit

Decodes the payload of an input added by the ERC-721 portal (depositERC721Token).

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) ‖ abi.encode(baseLayerData, execLayerData). There is no function selector, so make sure the input's msgSender is the ERC-721 portal before decoding its payload.

Usage

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

Parameters

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

Return Type

An Erc721Deposit object:

  • token (Address): token contract.
  • sender (Address): token sender.
  • tokenId (bigint): token identifier.
  • 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 72 bytes, or a viem decoding error if the data tail is malformed.