Utility repository for building and deploying smart contracts.
We will use deno, a modern alternative to Node that can work with TypeScript out of the box. You can install it by running:
curl -fsSL https://deno.land/install.sh | shWe can now compile the contracts located in the contracts/ directory:
deno task build [--filter <contract-name>] [--clean]This does the following:
- Compile the bytecode for each contract into
codgen/bytecode/* - Generate the abi for each contract into
codgen/abi/*.tsand the indexcodegen/abis.ts
Update tools/deploy.ts to include new contracts you want to deploy.
Make sure to specify the constructor arguments and the value, if needed.
Once you have the chain running (see Running the Revive Stack), deploy the contracts by running:
deno task deploy [--filter <contract-name>]This command will update the codegen/addresses.ts file with the deployed contract addresses, so that you can easily reference them in your apps.
Note: You can also test against
geth, the deployment code will detect the chain and deploy the right bytecode (evm or pvm).
There is an example cli in the cli directory that you can run to interact with the deployed contracts.
./cli/playground.tsThe deployment scripts use the following environment variables:
PRIVATE_KEY: The private key of the account to deploy from (optional)RPC_URL: The RPC endpoint URL (optional, defaults tohttp://localhost:8545)
You can create a .env file in the project root to set these variables (see .env.example for a template).
If PRIVATE_KEY is not set, the default account 0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac will be used. This account is pre-funded at genesis on local chains.
For more information on setting up and deploying to different environments, check out the Polkadot Smart Contracts documentation.
For local development, you'll need to build the development node and Ethereum RPC proxy.
First, clone the Polkadot SDK repository:
git clone https://github.com/paritytech/polkadot-sdk.git ~/polkadot-sdkSource the helper scripts to make the build commands available:
source scripts/node-env.shYou can add this to your shell profile (.bashrc, .zshrc, etc.) to make these commands available in every session.
Build both the development node and the Ethereum RPC proxy:
# Build the development node
dev-node build
# Build the Ethereum RPC bridge
eth-rpc buildThese commands will compile the binaries into ~/polkadot-sdk/target/debug/. The build process may take some time on the first run.
Note: The helper scripts use the
POLKADOT_SDK_DIRenvironment variable to locate the Polkadot SDK repository. By default, it points to~/polkadot-sdk. If you cloned the repository to a different location, you can override this by setting the environment variable before sourcing the scripts:export POLKADOT_SDK_DIR=/path/to/your/polkadot-sdk source scripts/node-env.sh
Once built, you can run each service individually:
# Run the development node
dev-node run
# In another terminal, run the Ethereum RPC bridge
eth-rpc run ws://localhost:9944Alternatively, you can run the complete development stack in tmux:
# Run both services in separate tmux panes
revive_dev_stack
# Or run with mitmproxy for traffic inspection
# Note: Requires mitmproxy setup first - https://github.com/pgherveou/mitmproxy
revive_dev_stack --proxy
# Run with custom consensus mode (e.g., manual-seal with 12 second block time)
revive_dev_stack --consensus manual-seal-12000To test contracts against standard Ethereum with Geth:
# Run geth in development mode (default port 8545)
geth-dev
# Or specify a custom port
geth-dev 8546Alternatively, you can run geth with mitmproxy in a tmux window:
# Run geth with mitmproxy in a tmux window
geth_stackThis will start a local Geth development node with HTTP RPC enabled, useful for comparing behavior between Revive and standard EVM environments.
When testing and debugging, you can record all eth_sendRawTransaction requests using the --record flag. This works with both eth-rpc and revive_dev_stack:
# Record requests when running eth-rpc
eth-rpc run ws://localhost:9944 --record
# Or specify a custom path for the recorded requests
eth-rpc run ws://localhost:9944 --record=/path/to/requests.log
# Record requests when running the full stack in tmux
revive_dev_stack --recordWhen --record is enabled, eth-rpc will:
- Log all output to console and
/tmp/eth-rpc.log - Extract and save all
eth_sendRawTransactionrequests to/tmp/eth-rpc-requests.log(or your custom path)
You can replay recorded requests using the scripts/run-all.sh script:
# Replay all recorded requests against localhost:8545
./scripts/run-all.shThis script will:
- Send each recorded transaction to the RPC endpoint
- Wait for transaction receipts
- Display status (✓ for success, ✗ for failure)
- Report any errors or failed transactions at the end
This is useful for regression testing - record a successful test session, then replay it against new builds to ensure compatibility.
The node-env.sh script provides several other useful functions for testing and development:
Run differential tests against the local dev node using the revive-differential-tests repository:
# Build the dev-node and generate the chainspec required by retester
dev-node build --retester
# Start the revive-dev-stack with the chainspec required by retester
revive_dev_stack --retester
# Run a specific differential test
retester_test "./resolc-compiler-tests/fixtures/solidity/complex/create/create2_many/test.json"Note: Requires the
revive-differential-testsrepository to be cloned. By default, it looks for the repository at~/github/revive-differential-tests. You can override this by setting theRETESTER_DIRenvironment variable:export RETESTER_DIR=/path/to/revive-differential-tests
Quickly configure cast CLI tool for different environments:
# Configure for local development
cast_local
# Configure for Westend Asset Hub testnet
cast_westend
# Configure for Passet Hub testnet
cast_passetThese functions set up the PRIVATE_KEY and ETH_RPC_URL environment variables, allowing you to use cast commands without repeatedly specifying credentials.
Build and run custom chain specs for testing on Westend Asset Hub or Passet Hub:
# Build and run Westend Asset Hub runtime locally
westend build # Build runtime and generate chain spec
westend run # Run with polkadot-omni-node
# Run the full Westend stack in tmux
westend_stack
# Similarly for Passet Hub (requires https://github.com/paseo-network/passet-hub checkout under ~/github/passet-hub-
passet build
passet run
passet_stack- Asset Hub documentation to learn more about building Smart Contracts on Asset Hub.
- viem documentation to learn more about the library used to interact with EVM contracts.