Deploy a Token on TAC EVM
Learn how to deploy a token on TAC EVM
In this guide, we will deploy and interact with a token on TAC EVM.
You can find the full code for this guide on GitHub.
Prerequisites
- Node.js
- NPM / Yarn
- Basic knowledge of Solidity
- An Ethereum wallet
Set up your environment
The first thing we need to do is set up our environment. In this guide, we will use Foundry to compile and deploy our smart contract. Foundry is a modern development toolchain for Ethereum, with a focus on simplicity and ease of use.
Install the Foundry CLI
To install the Foundry CLI, run the following command:
This will download foundryup. Then install Foundry by running,
Once Foundry is installed, you can verify the installation by running forge --version
.
Initialize a Foundry project
Next, we need to initialize a Foundry project. To do this, run the following command:
Then, navigate inside counter_contract, and your project structure should look like this:
Write your smart contract
Now, we need to write our smart contract. Create a file called token.sol
in the src
directory and add the following code:
In the above code, we have a constructor that initializes the token with a name, symbol, decimals, and total supply. We also have a transfer
, approve
, and transferFrom
function that allows us to transfer, approve, and transfer from tokens.
Test your smart contract
To add tests for your smart contract, create a file called token.t.sol
in the test
directory and add the following code:
The above code is a test for our smart contract. In the above code, we have a setUp
function that initializes the token and the owner, user1, and user2 addresses. We also have a test_InitialState
function that checks the initial state of the token, and a test_Transfer
function that tests the transfer
function.
Compile your smart contract
Before we compile our smart contract, create a new script in the script
directory called token.s.sol
, and add the following code:
Now, we can compile our smart contract by running the following command:
You should see compilation details such as:
Deploy your smart contract
Before we deploy our smart contract, make sure to add TAC EVM as a network in your wallet, and get some testnet TAC. You can get testnet TAC from the TAC Faucet and use the top right button to add TAC EVM as a network.
Next, To deploy your smart contract, run the following command:
You can replace <your-rpc-url>
with: https://turin.rpc.tac.build
Make sure to replace <your-private-key>
with your own Ethereum private key. Don’t share or expose your private key.
You can view the deployed contract on the TAC EVM Explorer.
That is it! You have successfully deployed a token on TAC EVM.