Skip to main content

Configure Foundry

Foundry is a blazing fast, portable, and modular toolkit for Ethereum application development. Get up and running with Foundry on Push Chain testnet.

Recommended Practice

Instead of reinventing your workflow, keep developing exactly as you would on Ethereumβ€”then just point Foundry at Push Chain RPCs and explorer.

Push Chain Specs
FieldValue
Network NamePush Chain Donut Testnet
RPC URLhttps://evm.rpc-testnet-donut-node1.push.org/, https://evm.rpc-testnet-donut-node2.push.org/
Chain ID42101
Currency SymbolPC
Block Explorer URLhttps://donut.push.network

Deploy Smart Contracts with Foundry​

1. Install Foundry​

To install Foundry, run:

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

Once the foundryup script is downloaded, follow the on-screen instructions to complete installation. After installation, restart your terminal and run:

foundryup

This will ensure you have the latest version of Foundry tools (forge, cast, anvil, and chisel) installed.



2. Create a New Project​

Create a new Foundry project:

forge init myToken
cd myToken

Install the OpenZeppelin contracts:

forge install OpenZeppelin/openzeppelin-contracts

This should create a new project with the following structure:

myToken/
β”œβ”€β”€ foundry.toml
β”œβ”€β”€ lib/
β”œβ”€β”€ out/
β”œβ”€β”€ script/
β”œβ”€β”€ src/
β”œβ”€β”€ test/


3. Configure for Push Chain​

Now simply modify your foundry.toml file to include Push Chain testnet configuration:

[profile.default]
src = "src"
out = "out"
libs = ["lib"]
remappings = ["@openzeppelin/=lib/openzeppelin-contracts/"]

# Push Chain Testnet configuration
[rpc_endpoints]
push_testnet = "https://evm.rpc-testnet-donut-node1.push.org/"
push_testnet_alt = "https://evm.rpc-testnet-donut-node2.push.org/"

# This is a placeholder - BlockScout doesn't require an API key but Foundry expects a key field
[etherscan]
push_testnet = { key = "blockscout", url = "https://donut.push.network/api", chain = 42101 }

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

This configuration includes:

  • Default project structure settings
  • RPC endpoints for Push Chain Donut testnet
  • BlockScout explorer configuration for contract verification


4. Write a Smart Contract​

Create a new file at src/MyToken.sol with the following ERC20 token implementation:

// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

/**
* @title MyToken
* @dev A simple ERC20 token for demonstration on PUSH CHAIN
*/
contract MyToken is ERC20, Ownable {
constructor() ERC20("MyToken", "MT") Ownable(msg.sender) {
_mint(msg.sender, 1000 * 10**18);
}

function decimals() public view virtual override returns (uint8) {
return 18;
}

function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}
}


5. Compile the Contract​

Compile your contract with:

forge build

If successful, you should see output similar to:

[β ’] Compiling...
[β ”] Compiling 18 files with 0.8.22
[β ‘] Solc 0.8.22 finished in 1.51s
Compiler run successful!


6. Deploy to Push Chain​

6.1. Set up your deployer account​

Following best security practices, we'll use Foundry's wallet management system instead of exposing private keys in environment variables:

cast wallet import myKeystore --interactive

You'll be prompted to enter your private key and create a password to encrypt it. This securely stores your key in ~/.foundry/keystores. Read more about Foundry Wallet Management.

warning

Never use accounts with significant funds for test deployments. Never store private keys in plain text or in your repository.

6.2. Get testnet tokens​

Ensure you have testnet tokens to pay for deployment gas fees. If you don't have any, use the Push Chain testnet faucet.

6.3. Deploy your contract​

forge create src/MyToken.sol:MyToken \
--rpc-url push_testnet \
--chain 42101 \
--account myKeystore \
--broadcast

This command:

  • Creates your MyToken contract
  • Uses the Push Chain testnet RPC
  • Specifies the correct chain ID (42101)
  • Uses your securely stored account
  • Broadcasts the transaction to the network

Deployment Results

If successful, you'll see output similar to:

Deployer: 0xa89523351BE1e2De64937AA9AF61Ae06eAd199C7
Deployed to: 0xF0f1199A048A39336dFD915F146470de1b5d6dAd
Transaction hash: 0x255e64bbe86253979f070b48db0868f6f108a47e7b7f94586bc869fbd2d98800

Save the contract address for verification and interaction later.



7. Verify the Contract​

Verify your contract on the Push Chain BlockScout explorer:

forge verify-contract \
--chain 42101 \
--verifier blockscout \
0xYourDeployedAddress \
src/MyToken.sol:MyToken

Note: Replace 0xYourDeployedAddress with your actual deployed contract address.

If successful, you'll see output similar to:

Start verifying contract `0xF0f1199A048A39336dFD915F146470de1b5d6dAd` deployed on 42101

Submitting verification for [src/MyToken.sol:MyToken] 0xF0f1199A048A39336dFD915F146470de1b5d6dAd.
Submitted contract for verification:
Response: `OK`
GUID: `f0f1199a048a39336dfd915f146470de1b5d6dad68494bd5`
URL: https://donut.push.network/address/0xf0f1199a048a39336dfd915f146470de1b5d6dad

Visit the provided URL to view your verified contract on the Push Chain explorer.

That's it! You have successfully deployed and verified your smart contract on Push Chain.

Next Steps​