Skip to main content
Version: v1.3

Register Tokens

caution

This method is now obsolete, use the new createNativeTokenFoundry method instead.

To properly use your native tokens, you should register them as ERC20 using the registerERC20NativeToken function from the ISC magic contract.

Example Code

Ownership

You might want to look into making the function ownable with, for example, OpenZeppelin so only owners of the contract can call certain functionalities of your contract.

1. Check the Storage Deposit

Check if the amount paid to the contract is the same as the required storage deposit and set the allowance.

require(msg.value == _storageDeposit*(10**12), "Please send exact funds to pay for storage deposit");
ISCAssets memory allowance;
allowance.baseTokens = _storageDeposit;
Payable

Instead of making the function payable, you could let the contract pay for the storage deposit. If so, you will need to change the require statement to check if the contract's balance has enough funds:

require(address(this).balance > _storageDeposit);

2. Register the Native Tokens

Register the native tokens specifying:

  • the foundry serial number
  • a name
  • a symbol
  • it's decimals
  • the allowance.
ISC.sandbox.registerERC20NativeToken(_foundrySN, _name, _symbol, _decimals, allowance);

3. Get the Contract's Address

Get the ERC20 contract address with erc20NativeTokensAddress:

address erc20address = ISC.sandbox.erc20NativeTokensAddress(_foundrySN);

Full Example Code

event ERC20Address(address erc20address);

function registerERC20NativeToken(uint32 _foundrySN, string calldata _name, string calldata _symbol, uint8 _decimals, uint64 _storageDeposit) public payable {
require(msg.value == _storageDeposit*(10**12), "Please send exact funds to pay for storage deposit");
ISCAssets memory allowance;
allowance.baseTokens = _storageDeposit;
ISC.sandbox.registerERC20NativeToken(_foundrySN, _name, _symbol, _decimals, allowance);
address erc20address = ISC.sandbox.erc20NativeTokensAddress(_foundrySN);
emit ERC20Address(erc20address);
}