1 - Contemporary Contracts
Dev Toolchain and Workspace Setup
Creating Your Smart Contract Workspace:
Use the
l1x-forgecommand to create a new project workspace:
l1x-forge new --name "your repository name" --template l1x-ftUnderstanding Configuration Files and Default Settings:
Explore
devbox.jsonandl1x-conf/l1x_chain_config.yamlfor workspace and chain configuration.
Getting Started with the Devbox Shell
Activating the Devbox Shell:
cd into your repository and activate the Devbox shell to install necessary packages:
devbox shellUsing Workspace Workflow Script Commands
List Available Script Commands:
View available script commands in your devbox shell:
devbox run -lSpecifying the Chain Type:
In the configuration file l1x-conf/l1x_chain_config.yaml, specify the chain type for deploying and working with the workspace contract. Choose between beta_mainnet or local_devnet based on your development and deployment needs.
Initializing Setup
Starting the Devnode Services:
To start the devnode services, use this command:
Checking DevNet Service Status:
To ensure everything is functioning smoothly, use the following commands to check the service status:
These commands provide insights into the DevNet service status, confirming that the services are initialized and operational.
Using Workspace Workflow Script Commands
This section introduces the workspace's workflow script commands that you can use. Here is a list of supported commands:
List Available Script Commands: To see a list of available script commands, use the following command in your devbox shell:
This will list all the available script commands, such as:
Building and Deploying the Smart Contract
Compile the Contract:
Compile your contract with the following command:
Deploying the Contract:
Deploy the compiled contract and note the displayed contract address:
Initializing the contract
Function Invocation
Invoke the ft_mint() Function:
Invoke
ft_mint()to mint tokens from Ava's account to Emma's account, updating the contract address in the filel1x-conf/scripts/010-20-uc-mint-ava-to-emma.json:
Invoke the ft_balance_of() Function:
Check the token balance status of Emma's account by invoking
ft_balance_of(), ensuring the contract address from step 9.2 is updated in the filel1x-conf/scripts/010-05-uc-check-emma-balance.json:
Cleanup and Troubleshooting
Stopping Devnode Services:
Stop the devnode services with this command:
Cleaning Up Service Resources and Storage:
Release resources and storage space with this command:
Contract | Code Explainer
Overview of FT Contract:
The FT (Fungible Token) Contract in the L1X platform is a standard implementation for handling fungible tokens within the ecosystem. It allows for the creation, transfer, and management of tokens that have identical value to each other, facilitating a wide range of decentralized applications and financial solutions.
Contract Structure and Code Explanation: The
L1xFtErc20struct in the code defines the main structure of the token contract. It holds metadata about the token, a map of account addresses to their balances, a map for allowances, and a variable for total supply.
L1xFtErc20 Structure
Initialization of the Contract: new Method
The new method is used to initialize the contract with metadata, account IDs, and amounts. It ensures that the function caller is the contract owner and then sets up the initial balances for the provided account IDs.
Minting Tokens: ft_mint Method
The ft_mint method allows the contract owner to mint new tokens for a specified recipient. It updates the total supply and the balance of the recipient.
Transferring Tokens: ft_transfer Method
ft_transfer MethodThe ft_transfer method allows a user to transfer a specified amount of tokens to a recipient account. The function ensures that the sender has enough balance to make the transfer.
Querying Balance: ft_balance_of Method
ft_balance_of MethodThe ft_balance_of method allows one to query the balance of a specific account in the contract. It returns the balance as a U128 type.
Last updated