Skip to content

How to deploy a contract to Sonieum Minato using Foundry

Stardust✨ edited this page Aug 26, 2025 · 4 revisions

Preparation

Before reading this wiki, please check the following wikis.
If you have completed the steps in them, you already have a fully synchronized Minato node and You have Minato ETH.

Pre-checks

Check node synchronization status

  • If the result returns false, synchronization is complete.
admin@Soneians:~/soneium-minato-node$ curl -X POST http://127.0.0.1:8545 \
  -H "Content-Type: application/json" \
  --data '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":1}'
{"jsonrpc":"2.0","id":1,"result":false}

Check if your wallet has Minato ETH

  • Confirm via your own RPC that your wallet holds 0.1 ETH.
admin@Soneians:~/soneium-minato-node$ curl -X POST http://127.0.0.1:8545 \
  -H "Content-Type: application/json" \
  --data '{"jsonrpc":"2.0","method":"eth_getBalance","params":["WALLET_ADDRESS","latest"],"id":1}'
{"jsonrpc":"2.0","id":1,"result":"0x16345785d8a0000"}
admin@Soneians:~/soneium-minato-node$ python3 -c 'print(int("0x16345785d8a0000",16)/1e18)'
0.1

Check the Minato chain ID

admin@Soneians:~$ curl -s -X POST http://127.0.0.1:8545 \
  -H "Content-Type: application/json" \
  --data '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}' | jq -r '.result'
0x79a
admin@Soneians:~$ printf "%d\n" 0x79a
1946

Deploying a contract to Minato node using Foundry

Install Foundry

admin@Soneians:~$ curl -L https://foundry.paradigm.xyz | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   167  100   167    0     0   1588      0 --:--:-- --:--:-- --:--:--  1575
100  2196  100  2196    0     0   6489      0 --:--:-- --:--:-- --:--:--  6489
Installing foundryup...

Detected your preferred shell is bash and added foundryup to PATH.
Run 'source /home/admin/.bashrc' or start a new terminal session to use foundryup.
Then, simply run 'foundryup' to install Foundry.
admin@Soneians:~/foundry$ exec $SHELL -l
admin@Soneians:~/foundry$ foundryup


.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx

 ╔═╗ ╔═╗ ╦ ╦ β•”β•—β•” ╔╦╗ ╦═╗ ╦ ╦         Portable and modular toolkit
 β• β•£  β•‘ β•‘ β•‘ β•‘ β•‘β•‘β•‘  β•‘β•‘ ╠╦╝ β•šβ•¦β•    for Ethereum Application Development
 β•š   β•šβ•β• β•šβ•β• β•β•šβ• ═╩╝ β•©β•šβ•  β•©                 written in Rust.

.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx

Repo       : https://github.com/foundry-rs/foundry
Book       : https://book.getfoundry.sh/
Chat       : https://t.me/foundry_rs/
Support    : https://t.me/foundry_support/
Contribute : https://github.com/foundry-rs/foundry/blob/master/CONTRIBUTING.md

.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx

Create a hello-foundry project

admin@Soneians:~$ forge init hello-foundry
Initializing /home/admin/hello-foundry...
Installing forge-std in /home/admin/hello-foundry/lib/forge-std (url: Some("https://github.com/foundry-rs/forge-std"), tag: None)
Cloning into '/home/admin/hello-foundry/lib/forge-std'...
remote: Enumerating objects: 2201, done.
remote: Counting objects: 100% (1043/1043), done.
remote: Compressing objects: 100% (147/147), done.
remote: Total 2201 (delta 964), reused 899 (delta 896), pack-reused 1158 (from 2)
Receiving objects: 100% (2201/2201), 723.85 KiB | 20.11 MiB/s, done.
Resolving deltas: 100% (1479/1479), done.
    Installed forge-std tag=v1.10.0@8bbcf6e3f8f62f419e5429a0bd89331c85c37824
    Initialized forge project
admin@Soneians:~$ cd hello-foundry
admin@Soneians:~/hello-foundry$ tree
.
β”œβ”€β”€ README.md
β”œβ”€β”€ foundry.lock
β”œβ”€β”€ foundry.toml
β”œβ”€β”€ lib
β”‚   └── forge-std
β”‚       β”œβ”€β”€ CONTRIBUTING.md
β”‚       β”œβ”€β”€ LICENSE-APACHE
β”‚       β”œβ”€β”€ LICENSE-MIT
β”‚       β”œβ”€β”€ README.md
β”‚       β”œβ”€β”€ foundry.toml
β”‚       β”œβ”€β”€ package.json
β”‚       β”œβ”€β”€ scripts
β”‚       β”‚   └── vm.py
β”‚       β”œβ”€β”€ src
β”‚       β”‚   β”œβ”€β”€ Base.sol
β”‚       β”‚   β”œβ”€β”€ Script.sol
β”‚       β”‚   β”œβ”€β”€ StdAssertions.sol
β”‚       β”‚   β”œβ”€β”€ StdChains.sol
β”‚       β”‚   β”œβ”€β”€ StdCheats.sol
β”‚       β”‚   β”œβ”€β”€ StdConstants.sol
β”‚       β”‚   β”œβ”€β”€ StdError.sol
β”‚       β”‚   β”œβ”€β”€ StdInvariant.sol
β”‚       β”‚   β”œβ”€β”€ StdJson.sol
β”‚       β”‚   β”œβ”€β”€ StdMath.sol
β”‚       β”‚   β”œβ”€β”€ StdStorage.sol
β”‚       β”‚   β”œβ”€β”€ StdStyle.sol
β”‚       β”‚   β”œβ”€β”€ StdToml.sol
β”‚       β”‚   β”œβ”€β”€ StdUtils.sol
β”‚       β”‚   β”œβ”€β”€ Test.sol
β”‚       β”‚   β”œβ”€β”€ Vm.sol
β”‚       β”‚   β”œβ”€β”€ console.sol
β”‚       β”‚   β”œβ”€β”€ console2.sol
β”‚       β”‚   β”œβ”€β”€ interfaces
β”‚       β”‚   β”‚   β”œβ”€β”€ IERC1155.sol
β”‚       β”‚   β”‚   β”œβ”€β”€ IERC165.sol
β”‚       β”‚   β”‚   β”œβ”€β”€ IERC20.sol
β”‚       β”‚   β”‚   β”œβ”€β”€ IERC4626.sol
β”‚       β”‚   β”‚   β”œβ”€β”€ IERC6909.sol
β”‚       β”‚   β”‚   β”œβ”€β”€ IERC721.sol
β”‚       β”‚   β”‚   β”œβ”€β”€ IERC7540.sol
β”‚       β”‚   β”‚   β”œβ”€β”€ IERC7575.sol
β”‚       β”‚   β”‚   └── IMulticall3.sol
β”‚       β”‚   └── safeconsole.sol
β”‚       └── test
β”‚           β”œβ”€β”€ CommonBase.t.sol
β”‚           β”œβ”€β”€ StdAssertions.t.sol
β”‚           β”œβ”€β”€ StdChains.t.sol
β”‚           β”œβ”€β”€ StdCheats.t.sol
β”‚           β”œβ”€β”€ StdConstants.t.sol
β”‚           β”œβ”€β”€ StdError.t.sol
β”‚           β”œβ”€β”€ StdJson.t.sol
β”‚           β”œβ”€β”€ StdMath.t.sol
β”‚           β”œβ”€β”€ StdStorage.t.sol
β”‚           β”œβ”€β”€ StdStyle.t.sol
β”‚           β”œβ”€β”€ StdToml.t.sol
β”‚           β”œβ”€β”€ StdUtils.t.sol
β”‚           β”œβ”€β”€ Vm.t.sol
β”‚           β”œβ”€β”€ compilation
β”‚           β”‚   β”œβ”€β”€ CompilationScript.sol
β”‚           β”‚   β”œβ”€β”€ CompilationScriptBase.sol
β”‚           β”‚   β”œβ”€β”€ CompilationTest.sol
β”‚           β”‚   └── CompilationTestBase.sol
β”‚           └── fixtures
β”‚               β”œβ”€β”€ broadcast.log.json
β”‚               β”œβ”€β”€ test.json
β”‚               └── test.toml
β”œβ”€β”€ script
β”‚   └── Counter.s.sol
β”œβ”€β”€ src
β”‚   └── Counter.sol
└── test
    └── Counter.t.sol

12 directories, 61 files

Create Hello World contract

admin@Soneians:~/hello-foundry$ cat src/HelloWorld.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract HelloWorld {
    string private greeting;

    constructor(string memory _greeting) {
        greeting = _greeting;
    }

    function greet() external view returns (string memory) {
        return greeting;
    }

    function setGreeting(string calldata _greeting) external {
        greeting = _greeting;
    }
}

Prepare deployment script

admin@Soneians:~/hello-foundry$ cat script/HelloWorld.s.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {Script} from "forge-std/Script.sol";
import {console2} from "forge-std/console2.sol"; 
import {HelloWorld} from "../src/HelloWorld.sol";

contract HelloWorldScript is Script {
    function run() external {
        uint256 deployerKey = vm.envUint("PRIVATE_KEY");

        vm.startBroadcast(deployerKey);
        HelloWorld hw = new HelloWorld("Hello, Soneium!");
        vm.stopBroadcast();

        console2.log("HelloWorld deployed at:", address(hw)); 
    }
}

Adjust foundry.toml

admin@Soneians:~/hello-foundry$ cat foundry.toml 
[profile.default]
src = "src"
out = "out"
libs = ["lib"]
chain_id = 1946

Configure .env with private key and RPC

  • Create .env file
admin@Soneians:~/hello-foundry$ cat .env 
PRIVATE_KEY=0x[secret key]
RPC_URL=http://127.0.0.1:8545
  • Load .env file
admin@Soneians:~/hello-foundry$ set -a; source .env; set +a

Compile & Deploy

admin@Soneians:~/hello-foundry$ forge build
[⠊] Compiling...
[β ”] Compiling 1 files with Solc 0.8.30
[β ’] Solc 0.8.30 finished in 401.46ms
Compiler run successful!
admin@Soneians:~/hello-foundry$ forge script script/HelloWorld.s.sol:HelloWorldScript \
  --rpc-url $RPC_URL \
  --broadcast \
  --private-key $PRIVATE_KEY
[⠊] Compiling...
No files changed, compilation skipped
Script ran successfully.

== Logs ==
  HelloWorld deployed at: 0x4B3a4b61304B242D022362a5C80d7fBc7ab25459

## Setting up 1 EVM.

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

Chain 1946

Estimated gas price: 0.000000505 gwei

Estimated total gas used for script: 526575

Estimated amount required: 0.000000000265920375 ETH

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

##### soneium-minato-testnet
βœ…  [Success] Hash: 0x870e4587b3bdf97638d01b58f25ad4da5160c13e3fdcec87d2a3db5bc192910a
Contract Address: 0x4B3a4b61304B242D022362a5C80d7fBc7ab25459
Block: 16427595
Paid: 0.000000000102479674 ETH (405058 gas * 0.000000253 gwei)

βœ… Sequence #1 on soneium-minato-testnet | Total Paid: 0.000000000102479674 ETH (405058 gas * avg 0.000000253 gwei)
                                                                                                                                                                                                           

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

ONCHAIN EXECUTION COMPLETE & SUCCESSFUL.

Transactions saved to: /home/admin/hello-foundry/broadcast/HelloWorld.s.sol/1946/run-latest.json

Sensitive values saved to: /home/admin/hello-foundry/cache/HelloWorld.s.sol/1946/run-latest.json

Verify operation

  • Execute contract
admin@Soneians:~/hello-foundry$ ADDR=0x4B3a4b61304B242D022362a5C80d7fBc7ab25459
admin@Soneians:~/hello-foundry$ cast call $ADDR "greet()(string)" --rpc-url $RPC_URL
"Hello, Soneium!"
  • Change contract state
admin@Soneians:~/hello-foundry$ cast send $ADDR "setGreeting(string)" "GM, Soneians!" --rpc-url $RPC_URL --private-key $PRIVATE_KEY


blockHash            0x45b43535375a1ed2572f6313effd39ca10fedbc12af6ac36b59f37f715ee5dcc
blockNumber          16428738
contractAddress      
cumulativeGasUsed    73843
effectiveGasPrice    100000252
from                 0x53869B88306EB505f0fC66DaE482D42033F85253
gasUsed              27687
logs                 []
logsBloom            0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
root                 
status               1 (success)
transactionHash      0xad638d5587682bf676c485512d93df1d8163be0b28c392bbdc8d4b7a7bfb2d61
transactionIndex     1
type                 2
blobGasPrice         
blobGasUsed          
to                   0x4B3a4b61304B242D022362a5C80d7fBc7ab25459
l1BaseFeeScalar      9736
l1BlobBaseFee        534
l1BlobBaseFeeScalar  1540079
l1Fee                16094870726
l1GasPrice           1033200781
l1GasUsed            1600
admin@Soneians:~/hello-foundry$ cast call $ADDR "greet()(string)" --rpc-url $RPC_URL
"GM, Soneians!"

References