Simple Token Transfer Tutorial
In this tutorial, we will walk you through the process of building a simple token transfer dApp using the IOTA Move language and the IOTA dApp kit. You will learn how to create a move package that enables token transfers on the IOTA blockchain and how to integrate it with a frontend application that interacts with the package functions. The tutorial covers everything from move package creation to frontend development, giving you a hands-on understanding of how token transfers work within the IOTA ecosystem. By the end, you'll have a fully functional dApp that allows users to transfer tokens effortlessly.
Simple Token Transfer Architecture Overview
Prerequisites
Create a Move Package
Run the following command to create a Move package
iota move new token_transfer_tutorial
This will generate a new Move package in a folder named token_transfer
.
Configure the IOTA CLI
To run the mint
function from the frontend app, you must be the owner of the package; otherwise, you cannot execute the function. To become the owner, you need to publish the package, and this process can only be done through the CLI. Note that the CLI and browser wallet extension use separate accounts. In the CLI, you can update the active address and private key to match the account used in the browser wallet extension. By aligning these accounts, you ensure the same account is used in both the CLI and the wallet extension, enabling seamless transactions in your frontend app.
Before publishing the package, you need to configure your IOTA CLI with your wallet details.
Navigate to the IOTA Configuration Directory
cd ~/.iota/iota_config/
Update the Private Key and Active Address
iota.keystore
: Replace the existing private key with your IOTA wallet private key.
client.yaml
: Replace the active_address
field with your IOTA wallet address.
Package Overview
init
- Executes at the time of publication of the package.
- Takes
MY_TOKEN
as a witness and the transaction context (ctx). - Uses the
coin::create_currency
function to create the token by specifying the name, symbol, and decimal precision of the token. - The
coin::create_currency
function returns a TreasuryCap, which allows the owner to mint and transfer the token, and the metadata of the token. - Transfers the metadata to the owner of the contract using
transfer::public_freeze_object(metadata)
andtransfer::public_transfer(treasury, ctx.sender())
.
loading...
mint
- Mints the token and transfers it to the recipient address.
- Can only be called by the owner of the contract.
- Creates a new object of the
MY_TOKEN
token using the TreasuryCap. - The TreasuryCap address (which was generated during the contract's publication) is required to mint the tokens.
- Transfers the minted tokens to the recipient after they are created.
loading...