Skip to Content

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-storage

Configure 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" 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_spec returns the version in force (2 is 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.
  • chain_id = 535600 sets what block.chainid returns in forge 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, since forge script and forked tests fail against /rpc/v1/eth; see Which endpoint to use. An eth_rpc_url in the profile would instead make forge test fork 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; } }

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 \ --broadcast

forge 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 deployer

cast call reads through eth_call, which sends no transaction and costs no gas:

cast call <CONTRACT_ADDRESS> "get()(uint256)" --rpc-url supra_devnet

The deployment and the set transaction appear on the Devnet explorer  under the contract’s address.

Last updated on