From af9fad9213d3e616b23f4850e6abca8fbefd4192 Mon Sep 17 00:00:00 2001 From: Dr-Electron Date: Tue, 20 Feb 2024 15:33:50 +0100 Subject: [PATCH] Add custom ERC20 functions --- .../docs/how-tos/token/erc20-native-token.md | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 docs/build/isc/v1.0.0-rc.6/docs/how-tos/token/erc20-native-token.md diff --git a/docs/build/isc/v1.0.0-rc.6/docs/how-tos/token/erc20-native-token.md b/docs/build/isc/v1.0.0-rc.6/docs/how-tos/token/erc20-native-token.md new file mode 100644 index 00000000000..dace4ebc0ff --- /dev/null +++ b/docs/build/isc/v1.0.0-rc.6/docs/how-tos/token/erc20-native-token.md @@ -0,0 +1,40 @@ +--- +description: How to use the custom functionality of ERC20NativeToken +image: /img/logo/WASP_logo_dark.png +tags: + - native token + - erc20 + - EVM + - how-to +--- + +# Custom ERC20 functions + +Once you [registered your native token as ERC20](./erc20-native-token.md) you can basically use it like any other ERC20 token, with functions like `transfer`, `balanceOf` and so on. But as the ERC20 token maps the native token on L2 there are some additional fetures. + +## Example Code + +1. Get your `ERC20NativeTokens` instance (In this case we will use `erc20NativeTokensAddress` and the Foundry serial number to get the contract address) +```solidity + ERC20NativeTokens token = ERC20NativeTokens( + ISC.sandbox.erc20NativeTokensAddress(_foundrySN) + ); +``` + +* `nativeTokenID` will give you the native token ID of the ERC20 token +```solidity + NativeTokenID memory id =token.nativeTokenID(); +``` + + +### Full Example Code + +```solidity + function nativeTokenID(uint32 _foundrySN) public view returns (bytes memory) { + ERC20NativeTokens token = ERC20NativeTokens( + ISC.sandbox.erc20NativeTokensAddress(_foundrySN) + ); + NativeTokenID memory id =token.nativeTokenID(); + return id.data; + } +```