Using Foundry
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 https://github.com/thundercore/foundry-thundercore
One Time Setup
Installing Foundry
See the Installation 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":
Encrypted Keystores
Foundry generates standard encrypted Ethereum keystore files under $HOME/.foundry/keystores
The format is widely supported
Private keys in the keystores can be exported with:
by using the `ethkey` utility from go-ethereum.
Obtaining Funds
You'll need some gas tokens to deploy contracts.
To test on ThunderCore testnet, you can get some testnet tokens from ThunderCore Testnet Faucet https://faucet-testnet.thundercore.com
For ThunderCore mainnet, see https://www.thundercore.com/buy-tt
Create A New Project
To start a new project with Foundry, use forge init:
The src folder may already contain Counter.sol, a minimal Solidity contract.
Setup Foundry For ThunderCore
Edit foundry.toml to contain:
Compiling
Run the command forge build to build the project.
And test the build with "forge test".
Deploy to ThunderCore Network
Edit script/Counter.s.sol and add "new Counter()" at the end of run():
Use "forge script" to deploy your contract to ThunderCore:
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.
Mainnet: https://explorer-mainnet.thundercore.com
Testnet: https://explorer-testnet.thundercore.com
Interact With The Counter Contract
We can read the Counter value via cast call:
We can increment the Counter value via "cast send":
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:
Created a new wallet in the Foundry keystore named deployer ($HOME/.foundry/deployer)
Obtained funds for gas to the deployer account
Created a new Foundry project
Configured that project for ThunderCore via foundry.toml
Deployed our contract to the ThunderCore blockchain
Interacted with our contract to read and write information
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
Last updated