ThunderCore
ThunderCoreThunderCore Bridge
  • ⚡Hello world
  • Developer Program
  • Network Details
    • ThunderCore Mainnet
    • ThunderCore Testnet
    • Token List
    • Smart Contract Services
    • Full Node Deployment
  • Develop on ThunderCore
    • Migrate from Ethereum
    • Using Foundry
    • Using Hardhat
    • Using Remix
    • Using Truffle
    • Deploy TT20
    • Deploy a DApp
    • Deploy a NFT
  • Develop on TT Wallet
    • DApp Submission
    • Deeplinking
    • Signing Messages
    • Ethereum Provider API
    • Token Listing
    • Advertising with TT Wallet
      • Logo size submission guideline
      • Promotional Package
      • How we help developers
    • Developer Build - TT Wallet (Android)
  • FAQs
  • Product / Protocol
    • Wallets
      • MetaMask
        • Create a MetaMask Wallet
        • Create multiple accounts
      • TT Wallet
    • ThunderCore Bridge
      • Architecture
      • Ethereum <> ThunderCore
      • BNB chain <> ThunderCore
      • Interact with ThunderCore Bridge
  • Tool
    • Game Development
      • MetaFab
    • DApp Development
      • Faucet
      • Random Number Generator
      • Oracles
      • Referral Library
      • TTSwap Resources
      • Wrapped TT Addresses
      • Multicall
      • Subgraph
      • Auth Service
      • Wallet Service
      • Node Service
Powered by GitBook
On this page
  • One Time Setup
  • Installing Foundry
  • Creating A Wallet
  • Encrypted Keystores
  • Obtaining Funds
  • Create A New Project
  • Setup Foundry For ThunderCore
  • Compiling
  • Deploy to ThunderCore Network
  • Check the deployed contract in Explorer
  • Interact With The Counter Contract
  • Conclusion
  1. Develop on ThunderCore

Using Foundry

Last updated 1 year ago

Foundry is a smart contract development toolchain that manages your dependencies, compiles your project, runs tests, deploys, and lets you interact with the chain from the CLI and via Solidity scripts.

See the finished code at

One Time Setup

Installing Foundry

See the chapter in the Foundry Book.

Creating A Wallet

You can use "cast wallet new" to create a ThunderCore compatible wallet.

Here we name our newly created wallet deployer by moving the encrypted keystore file generated by "cast":

$ k=$(cast wallet new --json ~/.foundry/keystores | jq -r .[0].path)
Enter secret:
$ mv $k ~/.foundry/keystores/deployer

Encrypted Keystores

Foundry generates standard encrypted Ethereum keystore files under $HOME/.foundry/keystores

  • The format is

  • See

Private keys in the keystores can be exported with:

 ethkey inspect ~/.foundry/keystores/deployer

Obtaining Funds

  • You'll need some gas tokens to deploy contracts.

Create A New Project

To start a new project with Foundry, use forge init:

$ forge init <project_name>

The src folder may already contain Counter.sol, a minimal Solidity contract.

Setup Foundry For ThunderCore

$ cd <project_name>
$ EDIT foundry.toml

Edit foundry.toml to contain:

[profile.default]
evm_version = "london"

[rpc_endpoints]
thunder-mainnet = "https://mainnet-rpc.thundercore.com"
thunder-testnet = "https://testnet-rpc.thundercore.com"

# See more config options
# https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options

Compiling

Run the command forge build to build the project.

$ forge build

And test the build with "forge test".

$ forge test

Deploy to ThunderCore Network

Edit script/Counter.s.sol and add "new Counter()" at the end of run():

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;

import {Script, console} from "forge-std/Script.sol";
import "../src/Counter.sol";

contract CounterScript is Script {
	function setUp() public {}

	function run() public {
    		vm.broadcast();
    		new Counter();
	}
}

Use "forge script" to deploy your contract to ThunderCore:

$ forge script --rpc-url thunder-testnet --broadcast --account deployer ./script/Counter.s.sol
[⠰] Compiling...
No files changed, compilation skipped
Enter keystore password:
Script ran successfully.

## Setting up 1 EVM.

==========================

Chain 18

Estimated gas price: 2360 gwei

Estimated total gas used for script: 138734

Estimated amount required: 0.32741224 ETH

==========================
##
Sending transactions [0 - 0].
⠁ [00:00:00] [#] 1/1 txes (0.0s)##
Waiting for receipts.
⠉ [00:00:12] [#] 1/1 receipts (0.0s)
##### 18
✅  [Success]Hash: 0xe459d759617b8f6054646cd0aa37e2c14db66a051747b0c32609b2e3c87c3d78
Contract Address: 0x8133D6f94ae2cB864540BF9a3c736dd6f6F2E426
Block: 1754750
Paid: 0.2454537 ETH (106719 gas * 2300 gwei)



==========================

ONCHAIN EXECUTION COMPLETE & SUCCESSFUL.
Total Paid: 0.2454537 ETH (106719 gas * avg 2300 gwei)

Transactions saved to: (...)/broadcast/Counter.s.sol/18/run-latest.json

Check the deployed contract in Explorer

Copy the address of your newly deployed contract from the output. Then go to the ThunderCore Blockchain Explorer, and paste the address in the Search by address field.

Interact With The Counter Contract

We can read the Counter value via cast call:

$ cast call --rpc-url thunder-testnet <YOUR_CONTRACT_ADDR> 'number()'
0x0000000000000000000000000000000000000000000000000000000000000000

We can increment the Counter value via "cast send":

$ cast send --rpc-url thunder-testnet --account deployer <YOUR_CONTRACT_ADDR> 'increment()'
Enter keystore password:

blockHash           	0x03cdd8cb4bafb1028d3893ac34abd68b2f92a0b13c193dcf4b202812a4d2225d
(...)

After a successful transaction that calls increment , reading the counter value again should now return 1 instead of 0.

Conclusion

In this guide, we've accomplished:

  1. Created a new wallet in the Foundry keystore named deployer ($HOME/.foundry/deployer)

  2. Obtained funds for gas to the deployer account

  3. Created a new Foundry project

  4. Configured that project for ThunderCore via foundry.toml

  5. Deployed our contract to the ThunderCore blockchain

  6. Interacted with our contract to read and write information

by using the `ethkey` utility from .

To test on ThunderCore testnet, you can get some testnet tokens from ThunderCore Testnet Faucet

For ThunderCore mainnet, see

Mainnet:

Testnet:

And that's the basics of how to develop on ThunderCore via Foundry! Remember the finished code is available at

https://github.com/thundercore/foundry-thundercore
Installation
widely supported
Web3 Secret Storage Definition
go-ethereum
https://faucet-testnet.thundercore.com
https://www.thundercore.com/buy-tt
https://explorer-mainnet.thundercore.com
https://explorer-testnet.thundercore.com
https://github.com/thundercore/foundry-thundercore