Deploying the escrow contract

1.1 Set up project

Clone project:

$ git clone https://github.com/tashigg/tce-escrow-contract.git

Build:

$ npm i

$ forge build

Test:

$ forge test

Create file .env:

$ cd tce-escrow-contract

$ cp .env.example .env

1.2 Set up wallet

1.2.1 Create wallet

You must have an account in the EVM platform to deploy smart contracts. To have an account, you need to create a wallet. There are many E-Wallet Apps that allow you to create an account:

  • Metamask

  • Phantom

  • AgentX

But the most popular is metamask. We will use metamask in this tutorial.

Steps:

  1. Add extension to your browser

  2. Create a new wallet. Accept agreements, follow prompts and create a password.

  3. Secure wallet

  4. Show Secret Recovery Phrase

  5. Take a screenshot to save the secret recovery phrase. Any party who knows this recovery phrase can control the account, and can withdraw or transfer all tokens in the account, so keep the recovery phrase secret. Follow prompts to confirm that you have saved the secret recovery phrase.

  6. You have successfully created a Metamask wallet with a new account. You should pin the Metamask wallet to your web browser.

1.2.2 Get Private Key

You will need the account's private key to deploy smart contracts. Like the secret recovery phrase, any party who knows this private key can control the account, so keep it secret.

Steps:

  1. Open Metamask, select the desired account

  2. Open account details

  3. Show private key. Enter your wallet password and follow prompts to show the key.

  4. Copy the private key

1.2.3 Get Public Key

Open Metamask and copy the public key:

1.2.4 Faucet

Your account balance must be sufficient to pay the smart contract deployment fee. If your balance account is sufficient, you can skip this section.

We will use the Polygon network in this tutorial. The faucet for the polygon network can be found here: https://faucet.polygon.technology/

1.3 RPC Endpoints

Different networks have different RPC endpoints. We've listed them here, but you shouldn't need to manually input any of these because we've provided user-friendly aliases to these endpoints in the foundry.toml file. For more info, see section 1.6

1.4 Set Up API Scan Key

You will need an API key to verify smart contracts.

In this tutorial we will use the Polygon network. If you already have an API key or don’t need to verify your smart contract, you can skip this section.

Steps:

  1. Login: https://polygonscan.com -> Sign In

  2. Create API Key:

  3. Generate API key. You need to enter your app name.

  4. Get API Key

1.5 Config

Configure the .env file:

API_KEY_POLYGONSCAN = "Your_PolygonScan_API_Key" PRIVATE_KEY = "Your_Private_Key"

  • API_KEY_POLYGONSCAN: Your Polygon scan API Key.

  • PRIVATE_KEY: Your account private key. Copy and Paste private key. (Note: you may need to add "0x" to head of string)

1.6 Deploy & Verify Smart Contract

The foundry.toml file provides user-friendly aliases for the RPC endpoints of various networks. This means you won't need to manually type the endpoint URL in any commands.

Network

Mainnet Alias

Testnet Alias

Polygon

polygon

polygon_amoy

Bsc

bsc

bsc_testnet

Base

base

base_sepolia

Blast

blast

blase_sepolia

Avalanche

avalanche

avalanche_fuji

Arbitrum

arbitrum

arbitrum_sepolia

Optimism

optimism

optimism_sepolia

ImmutableX

immutableX

immutable_testnet

Ronin

ronin

ronin_saigon

Deploy:

$ forge script script/SessionManager.s.sol:SessionManagerScript --broadcast --rpc-url <network alias>

Deploy and Verify:

$ forge script script/SessionManager.s.sol:SessionManagerScript --broadcast --rpc-url <alias network> --verify

Example:

Deploy:

$ forge script script/SessionManager.s.sol:SessionManagerScript --broadcast --rpc-url polygon_amoy

Deploy & verify

$ forge script script/SessionManager.s.sol:SessionManagerScript --broadcast --rpc-url polygon_amoy --verify

Last updated