Skip to content
Logo

decodeDeposit

Decodes the payload of an input as a portal deposit, dispatching on the input's msgSender: if it is one of the portal deployment addresses, the payload is decoded with the corresponding decode function (decodeEtherDeposit, decodeErc20Deposit, decodeErc721Deposit, decodeErc1155SingleDeposit or decodeErc1155BatchDeposit).

The portal deployment addresses come from the same pinned rollups-contracts release as the ABIs, and are also exported (etherPortalAddress, erc20PortalAddress, erc721PortalAddress, erc1155SinglePortalAddress, erc1155BatchPortalAddress).

Usage

import { ,  } from "@cartesi/codec";
 
const  = ("0x...");
const  = ();
 
if () {
  switch (.) {
    case "EtherDeposit":
      .(., .);
      break;
    case "Erc20Deposit":
      .(., ., .);
      break;
    case "Erc721Deposit":
      .(., ., .);
      break;
    case "Erc1155SingleDeposit":
      .(., ., .);
      break;
    case "Erc1155BatchDeposit":
      .(., ., .);
      break;
  }
} else {
  // not a deposit: a regular input sent by `input.msgSender`
}

Parameters

  • input: a decoded input — only the msgSender and payload fields are used. The payload may be a Hex string or a Uint8Array.

Return Type

A Deposit union discriminated by the type field ("EtherDeposit", "Erc20Deposit", "Erc721Deposit", "Erc1155SingleDeposit" or "Erc1155BatchDeposit"), where each variant carries the fields of the corresponding deposit type.

Byte fields follow the representation of the payload: 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 payload — no data is copied.

Returns undefined if msgSender is not a portal, i.e. the input is not a deposit.

Errors

Throws if msgSender is a portal but the payload is malformed.