The FunToken mechanism on Nibiru facilitates the seamless connection of fungible tokens across different environments, such as ERC20 tokens and Bank Coins. This feature enhances interoperability, improves liquidity, and elevates the user experience. It also promotes ecosystem growth by bridging Ethereum-based protocols with Nibiru’s interchain assets.
The FunToken module on Nibiru Chain allows users to create and manage multiple fungible tokens using unique subdenominations. The creator of a token automatically gains "admin" privileges over it.
With NibiJS, users can perform the following operations on FunTokens:
Create FunToken
Convert Coin to EVM
All operations are executed using the NibiruTxClient class, which facilitates communication with the blockchain.
To interact with FunTokens, you need to connect your wallet to a NibiruTxClient. This client enables the use of the signAndBroadcast method for signing transactions.
To create a FunToken, you need a minimum balance of 10,000 NIBI, in addition to the transaction's gas fee. This amount is required as a Create FunToken Fee.
Copy
import{ EncodeObject }from"@cosmjs/proto-signing";import{ MsgCreateFunToken, MsgCreateFunTokenResponse }from"@nibiruchain/nibijs/dist/src/protojs/eth.evm.v1/tx";constcreateFunToken=async()=>{const denom ="tf/nibi1creator-address/subdenom";// Replace with the actual denominationconstmsgs: EncodeObject[]=[{typeUrl:"/eth.evm.v1.MsgCreateFunToken",value: MsgCreateFunToken.fromPartial({fromBankDenom: denom,sender: address,// Your wallet address}),},];const fee ="auto";// Automatically calculate transaction feeconst tx =await txClient.signAndBroadcast(address, msgs, fee);const result = MsgCreateFunTokenResponse.decode(tx.msgResponses[0].value);
console.log("Created FunToken Response:", result);};
Convert bank to its ERC20 representation and send to the EVM account adress
Copy
import{ EncodeObject }from"@cosmjs/proto-signing";import{ MsgConvertCoinToEvm, MsgConvertCoinToEvmResponse }from"@nibiruchain/nibijs/dist/src/protojs/eth.evm.v1/tx";constconvertCoinToEvmResponse=async()=>{const denom ="tf/nibi1creator-address/subdenom";// Replace with the actual denominationconstmsgs: EncodeObject[]=[{typeUrl:"/eth.evm.v1.MsgConvertCoinToEvm",value: MsgConvertCoinToEvm.fromPartial({toEthAddr:"0xRecipientEthAddress",// Replace with the recipient's Ethereum addresssender: address,// Your wallet addressbankCoin:{ denom,amount:"1000"},// Specify the Bank Coin denomination and amount}),},];const fee ="auto";// Automatically calculate transaction feeconst tx =await txClient.signAndBroadcast(address, msgs, fee);const result = MsgConvertCoinToEvmResponse.decode(tx.msgResponses[0].value);
console.log("Converted Coin to EVM Response:", result);};
Retrieve details about a specific FunToken mapping:
Copy
const token ="0xTokenAddressOrDenomination";// Either the ERC20 contract address or the Bank Coin denominationconst queryFunTokenInfo =await txClient.nibiruExtensions.query.eth.funTokenMapping({ token });
console.log("FunToken Mapping:", queryFunTokenInfo);