Skip to content

withdrawERC1155

Withdraw ERC-1155 tokens from one user and returns a Voucher to the recipient on L1. The voucher still need to be created through a createVoucher call.

Usage

The following example withdraws the entire balance of token id 1 of the user who is submitting an input to the application.

import { createApp } from "@deroll/app";
import { createWallet } from "@deroll/wallet";
 
// create app
const app = createApp({ url: "http://127.0.0.1:5004" });
 
// create wallet
const wallet = createWallet();
 
app.addAdvanceHandler(wallet.handler);
 
const token = "0x04d724738873CB6a86328D2EbAEb2079D715e61e"; // ERC-1155 address
app.addAdvanceHandler(async ({ metadata }) => {
    const user = metadata.msg_sender;
    const value = wallet.erc1155BalanceOf(token, user, 1n);
    if (value > 0) {
        const voucher = wallet.withdrawERC1155(token, user, 1n, value, "0x"); 
        await app.createVoucher(voucher);
    }
    return "accept";
});

Returns

Type: Voucher

Parameters

Type: Address

Address of ERC-1155 token.

Type: string

User to withdraw from.

Type: bigint

Id of the token.

Type: bigint

Amount to withdraw.

Type: Hex

Extra payload to pass to the L1 voucher.