Hello World on TAC EVM
Learn how to deploy and interact with a smart contract on TAC EVM
In this guide, we will deploy and interact with a smart contract 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 Hello.sol
in the src
directory and add the following code:
The contract has two functions: getGreeting
and setGreeting
.
The getGreeting
function returns the current greeting, and the setGreeting
function sets a new greeting. The GreetingChanged
event is emitted whenever the greeting is changed.
Test your smart contract
To add tests for your smart contract, create a file called Hello.t.sol
in the test
directory and add the following code:
The above code is a test for our smart contract. It tests the initial greeting, the setGreeting
function, and the GreetingChanged
event.
Compile your smart contract
Before we compile our smart contract, create a new script in the script
directory called hello.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 and interacted with a smart contract on TAC EVM.