Foundry
This page sets up a Foundry project for SupraEVM on Devnet, deploys a contract and calls it. The deploying address must hold SUPRA; see Funding an account.
Create a project
forge init supra-storage
cd supra-storageConfigure the project
In the foundry.toml that forge init created, add evm_version and chain_id to the existing
[profile.default] table, and add an [rpc_endpoints] table:
[profile.default]
src = "src"
out = "out"
libs = ["lib"]
evm_version = "osaka"
solc_version = "0.8.34"
chain_id = 535600
[rpc_endpoints]
supra_devnet = "https://rpc-devnet.supra.com/rpc/v1/eth/wallet_integration"evm_version = "osaka"compiles for Osaka, the EVM version SupraEVM targets. Governance sets it;0x1::evm_config::current_specreturns the version in force (2is Osaka). Foundry’s default EVM version depends on the Foundry release, so set it explicitly. EVM version lists the versions that execute here and the compiler versions that support them.solc_version = "0.8.34"pins the compiler. The Solidity libraries the other EVM pages import declarepragma solidity 0.8.34, and Foundry 1.5.1’s compiler auto-detection does not resolve that version for them.chain_id = 535600sets whatblock.chainidreturns inforge test, so a test sees Devnet’s value.[rpc_endpoints]names the endpoint, so a command can pass--rpc-url supra_devnet. It is the wallet-integration endpoint, sinceforge scriptand forked tests fail against/rpc/v1/eth; see Which endpoint to use. Aneth_rpc_urlin the profile would instead makeforge testfork Devnet.
Write a contract
Create src/SimpleStorage.sol:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract SimpleStorage {
uint256 public storedData;
function set(uint256 x) public {
storedData = x;
}
function get() public view returns (uint256) {
return storedData;
}
}Test the contract
Create test/SimpleStorage.t.sol:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Test} from "forge-std/Test.sol";
import {SimpleStorage} from "../src/SimpleStorage.sol";
contract SimpleStorageTest is Test {
SimpleStorage store;
function setUp() public {
store = new SimpleStorage();
}
function test_Set() public {
store.set(42);
assertEq(store.get(), 42);
}
function test_ChainId() public view {
assertEq(block.chainid, 535600);
}
}forge testforge test runs the tests in the EVM version and with the chain ID the project sets, and sends
nothing to Devnet.
Import the deploying key
Import the key into an encrypted keystore once:
cast wallet import deployer --interactive--interactive prompts for the private key and a password, and stores the key encrypted under the
name deployer. Commands then take --account deployer and prompt for the password, so the key is
never written into the project. To use a StarKey account, export its EVM private key as described in
Exporting a private key.
Build and deploy
forge build
forge create src/SimpleStorage.sol:SimpleStorage \
--rpc-url supra_devnet \
--account deployer \
--broadcastforge create prints the contract’s address after Deployed to:. Without --broadcast, it
performs a dry run.
Without --gas-price, Foundry sends an EIP-1559 transaction and estimates its fee from the endpoint,
which reports the floor. If you set --gas-price — the maxFeePerGas of an EIP-1559 transaction,
or with --legacy the gas price of a legacy one — it must be at or above
the gas price floor. A deployment must also fit
within the per-transaction gas limit.
Call the contract
cast send submits a transaction that calls a function:
cast send <CONTRACT_ADDRESS> "set(uint256)" 42 \
--rpc-url supra_devnet \
--account deployercast call reads through eth_call, which sends no transaction and costs no gas:
cast call <CONTRACT_ADDRESS> "get()(uint256)" --rpc-url supra_devnetThe deployment and the set transaction appear on the Devnet explorer
under the contract’s address.