Deploy a contract
Simulate a contract’s deployment, then send it, with Foundry or viem, and what differs from Ethereum.
Before you deploy
- Hold ETH on Robinhood Chain for gas, in an account whose key you have.
- Keep that key in Foundry’s keystore or in an environment variable, and never in a file you commit.
- Deploy to the testnet first. Its ETH comes from Robinhood’s faucet, and its RPC is Robinhood’s public one,
rpc.testnet.chain.robinhood.com.
The Network page has both networks’ chain IDs, URLs and explorers.
With Foundry
forge init makes a project with a Counter contract and a script that deploys it.
cast wallet import keeps your key encrypted in Foundry’s keystore, under the name you give it.
Without --broadcast, the script runs against the chain and prints the gas and the ETH it would take. Nothing is sent.
With --broadcast, the transaction is signed and sent.
forge init counter && cd counter
cast wallet import deployer --interactive
RPC=https://robinhood-mainnet.rpc.blockhash.xyz/v1
KEY="<your key>"
# run against the chain, with the gas and ETH it takes printed: nothing is sent
forge script script/Counter.s.sol --rpc-url $RPC/$KEY --account deployer
# signed and sent
forge script script/Counter.s.sol --rpc-url $RPC/$KEY --account deployer --broadcastWith viem
The contract’s ABI and bytecode are in the file forge build writes.
viem’s robinhood chain carries the chain ID, so a transaction is signed for Robinhood Chain alone.
The receipt names the new contract’s address.
import { createPublicClient, createWalletClient, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { robinhood } from 'viem/chains'
import counter from './out/Counter.sol/Counter.json' with { type: 'json' }
const RPC = 'https://robinhood-mainnet.rpc.blockhash.xyz/v1'
const transport = http(`${RPC}/${process.env.KEY}`)
const account = privateKeyToAccount(process.env.PRIVATE_KEY)
const client = createPublicClient({ chain: robinhood, transport })
const wallet = createWalletClient({ account, chain: robinhood, transport })
const hash = await wallet.deployContract({ abi: counter.abi, bytecode: counter.bytecode.object })
const { contractAddress } = await client.waitForTransactionReceipt({ hash })
console.log(contractAddress)What differs from Ethereum
block.numberis Ethereum’s block number, not Robinhood Chain’s. ArbSys’sarbBlockNumber(), at0x0000000000000000000000000000000000000064, is the chain’s own.block.prevrandaois always 1, so it is no source of random numbers. Blockhash VRF gives a contract random numbers with a proof.- A contract’s code may be up to 96 KB, and its init code up to 192 KB.
- A transaction’s fee pays for its gas on Robinhood Chain and for posting its data to Ethereum. An estimate of its gas counts both.
- The sequencer orders transactions as they arrive, so a higher fee does not move one ahead.
- Robinhood Chain has 100 ms block times: ten blocks a second.