Skip to main content
Version: v1.1

Custom ERC20 Functions

Once you registered your native token as ERC20 you can use it like any other ERC20 token, with functions like transfer, balanceOf, etc. But, as the ERC20 token maps the native token on L2, there are some additional ISC features you can take advantage of.

Example Code

Get Your nativeTokenID

You can use the erc20NativeTokensAddress function and the Foundry serial number to get the contract address:

ERC20NativeTokens token = ERC20NativeTokens(
ISC.sandbox.erc20NativeTokensAddress(_foundrySN)
);
  • nativeTokenID will give you the native token ID of the ERC20 token:
NativeTokenID memory id =token.nativeTokenID();

Full Example Code

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

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

contract MyNativeToken {

function nativeTokenID(uint32 _foundrySN) public view returns (bytes memory) {
ERC20NativeTokens token = ERC20NativeTokens(
ISC.sandbox.erc20NativeTokensAddress(_foundrySN)
);
NativeTokenID memory id = token.nativeTokenID();
return id.data;
}
}