Skip to main content

Send Assets and Tokens to L1

Accounts in ISC

Learn more about the different types of accounts.

info

ShimmerEVM has 18 decimal places, while Shimmer has 6. This means that any decimals beyond the 6th will be ignored by Shimmer, even though you can see them on ShimmerEVM. Please keep this in mind while sending your tokens to L1.

This guide will show you how to use the ISC sandbox interface to send assets from L2 to L1. This includes base tokens, native tokens, and NFTs. Before you can send these assets, you need to know how you get them on L2 and how you allow a contract to use them.

Note that assets on L1 require a storage deposit; therefore, the number of base tokens sent to L1 should cover at least the storage deposit required to hold the assets on L1.

Explanation

First, you will find out what assets this contract is allowed to take from the caller by calling the ISC.sandbox.getAllowanceFrom() function.

ISCAssets memory allowance = ISC.sandbox.getAllowanceFrom(msg.sender);

Then you take the allowance, which will transfer the assets from the caller to the contract.

ISC.sandbox.takeAllowedFunds(msg.sender, allowance);

Finally, you can send the assets to the specified L1 address. This will create an output to hold said assets. You can use additional options to add the timelock and expiration unlock conditions to the output.

ISCSendMetadata memory metadata;
ISCSendOptions memory options;
ISC.sandbox.send(to, allowance, false, metadata, options);

Full Example Code

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "@iota/iscmagic/ISC.sol";

contract L1Assets {
function withdraw(L1Address memory to) public {
ISCAssets memory allowance = ISC.sandbox.getAllowanceFrom(msg.sender);
ISC.sandbox.takeAllowedFunds(msg.sender, allowance);

ISCSendMetadata memory metadata;
ISCSendOptions memory options;
ISC.sandbox.send(to, allowance, false, metadata, options);
}
}