Skip to content

withdrawBatchERC1155

Withdraw multiple 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 and 2 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 value1 = wallet.erc1155BalanceOf(token, user, 1n);
    const value2 = wallet.erc1155BalanceOf(token, user, 2n);
    if (value1 > 0 && value2 > 0) {
        const voucher = wallet.withdrawBatchERC1155( 
            token, 
            user, 
            [1n, 2n], 
            [value1, value2], 
            "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[]

Ids of the token.

Type: bigint[]

Amounts to withdraw.

Type: Hex

Extra payload to pass to the L1 voucher.