This guide will walk you through the process of deploying your Solidity smart contracts to the TAC EVM Layer using Foundry. By the end, you’ll have successfully deployed a contract that can interact with the TON ecosystem through the TON Adapter.

TAC provides a standard EVM environment, allowing you to use modern tools like Foundry for smart contract development and deployment.

Prerequisites

Before you begin, make sure you have the following:

  • An Ethereum wallet with private key
  • Basic familiarity with Solidity and smart contract development
  • Some TAC tokens for gas fees (available from the testnet faucet for testing)

Step 1: Install Foundry

If you haven’t already installed Foundry, start by setting it up on your system.

1

Install Foundry

curl -L https://foundry.paradigm.xyz | bash

After the installation script completes, run:

foundryup
2

Verify installation

forge --version

You should see version information for forge, cast, and anvil.

Step 2: Create a New Foundry Project

1

Initialize a new Foundry project

forge init tac-foundry-demo
cd tac-foundry-demo

This creates a new Foundry project with a basic structure.

2

Explore the project structure

Foundry creates several directories:

  • src/: Directory for your smart contracts
  • test/: Directory for your tests
  • script/: Directory for deployment scripts
  • lib/: Directory for dependencies
  • foundry.toml: Foundry configuration file

Step 3: Write a Smart Contract

Let’s create a simple smart contract to deploy to TAC.

1

Create a contract file

Replace the content of src/Counter.sol with our SimpleStorage contract:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

contract SimpleStorage {
uint256 private value;
address public owner;

event ValueChanged(uint256 indexed oldValue, uint256 indexed newValue, address by);

constructor() {
    owner = msg.sender;
}

function setValue(uint256 newValue) public {
    uint256 oldValue = value;
    value = newValue;
    emit ValueChanged(oldValue, newValue, msg.sender);
}

function getValue() public view returns (uint256) {
    return value;
}
}
2

Create a deployment script

Create a new file in the script directory:

touch script/DeploySimpleStorage.s.sol

Add the following code to script/DeploySimpleStorage.s.sol:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import "forge-std/Script.sol";
import "../src/Counter.sol";

contract DeploySimpleStorage is Script {
    function run() external {
        uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
        
        vm.startBroadcast(deployerPrivateKey);
        
        SimpleStorage simpleStorage = new SimpleStorage();
        
        console.log("SimpleStorage deployed to:", address(simpleStorage));
        
        vm.stopBroadcast();
    }
}

Step 4: Configure Foundry for TAC

1

Create a .env file for your private key

touch .env

Add your private key to the .env file:

PRIVATE_KEY=your_private_key_here

Never commit your .env file to version control. Add it to your .gitignore file.

2

Update foundry.toml

Update the foundry.toml file to include the TAC network configurations:

[profile.default]
src = 'src'
out = 'out'
libs = ['lib']
solc = "0.8.17"

[rpc_endpoints]
tac_testnet = "https://turin.rpc.tac.build"

[etherscan]
tac_testnet = { key = "" }

Step 5: Get Testnet TAC Tokens

Before deploying to the testnet, you’ll need some TAC tokens to pay for gas fees.

1

Add TAC Testnet to your wallet

Add the TAC testnet to your MetaMask or other Ethereum wallet with the following details:

2

Get testnet tokens from the faucet

Visit the TAC Testnet Faucet and follow these steps:

  1. Connect your wallet
  2. Enter your wallet address
  3. Submit the request
  4. Wait for the tokens to arrive in your wallet

Step 6: Compile the Contract

1

Compile the contracts

forge build

You should see output indicating successful compilation.

Step 7: Deploy the Contract to TAC Testnet

Now, let’s deploy the contract to the TAC testnet.

1

Load environment variables

source .env
2

Deploy the contract

forge script script/DeploySimpleStorage.s.sol --rpc-url tac_testnet --broadcast --verify

If you encounter issues with verification, you can deploy without it:

forge script script/DeploySimpleStorage.s.sol --rpc-url tac_testnet --broadcast

You should see output with the deployment transaction and contract address.

3

Verify the deployment

You can verify your deployment by checking the TAC Turin Explorer:

  1. Visit TAC Turin Explorer
  2. Search for your contract address
  3. Confirm the contract details and transaction history

Step 8: Make Your Contract Accessible from TON

To make your contract accessible from TON wallets, you’ll need to create a proxy contract. This is covered in detail in the Build a Proxy Contract guide, but here’s a brief overview:

1

Create a proxy contract

Create a proxy contract that connects to your SimpleStorage contract and handles cross-chain messages from TON.

2

Deploy the proxy contract

Deploy the proxy contract to the TAC EVM Layer using the same Foundry workflow.

3

Connect with frontend

Use the TAC SDK to connect your frontend application to the proxy contract, enabling TON wallet interactions.

Next Steps

Congratulations! You’ve successfully deployed a smart contract to the TAC EVM Layer using Foundry. Now you can:

Was this page helpful?