Skip to content

Add pallet-revive to Your Runtime

Introduction

pallet-revive adds smart contract support to a Polkadot SDK runtime, and the Ethereum JSON-RPC adapter (eth-rpc) lets Ethereum tools talk to a chain that runs it. For an overview of what the pallet provides, see Add Smart Contract Functionality. This guide walks through the changes you make to your runtime:

  • Add the pallet-revive dependency.
  • Configure transaction fees in the way the pallet requires.
  • Define the transaction extension and extrinsic types that let the runtime accept Ethereum transactions.
  • Implement the pallet's Config trait, including the chain ID and precompiles.
  • Add the pallet to the runtime and implement the runtime APIs that eth-rpc calls.

The code in this guide comes from runtimes in the Polkadot SDK at release polkadot-stable2609-1:

Note

The pallet-revive Config trait changes between Polkadot SDK releases. For example, the Polkadot SDK master branch adds a MaxOutsideFrameLogs item that polkadot-stable2609-1 does not have. Compare the code in this guide with the reference runtimes of the release your runtime uses.

Prerequisites

Before you begin, make sure you have:

Add the Dependency

How you add the dependency depends on how your runtime imports Polkadot SDK crates.

If your runtime depends on the polkadot-sdk umbrella crate, add pallet-revive to its features in runtime/Cargo.toml. The Revive dev runtime's Cargo.toml uses this approach:

runtime/Cargo.toml
polkadot-sdk = { workspace = true, features = [
    "pallet-balances",
    "pallet-revive",
    "pallet-sudo",
    "pallet-timestamp",
    "pallet-transaction-payment",
    # ... other features
] }

The polkadot-sdk/std entry in your std feature list also enables the standard library features of pallet-revive.

If your runtime depends on individual crates, add pallet-revive and propagate its features. The Asset Hub Westend Cargo.toml uses this approach:

runtime/Cargo.toml
[dependencies]
pallet-revive = { workspace = true }

[features]
runtime-benchmarks = [
    # ... other features
    "pallet-revive/runtime-benchmarks",
]
try-runtime = [
    # ... other features
    "pallet-revive/try-runtime",
]
std = [
    # ... other features
    "pallet-revive/std",
]

Configure Transaction Fees

pallet-revive maps Ethereum gas to Polkadot SDK weight and fees, and this mapping depends on the fee structure. The pallet supports only one WeightToFee implementation for pallet_transaction_payment: BlockRatioFee, which enforces a ratio between ref_time and proof_size fees that matches their distribution in the block limits.

Set WeightToFee in your pallet_transaction_payment::Config implementation. The kitchensink runtime uses:

runtime/src/lib.rs
impl pallet_transaction_payment::Config for Runtime {
    // ... other configuration
    type WeightToFee = pallet_revive::evm::fees::BlockRatioFee<1, 1, Self, Balance>;
}

The two numeric parameters define the rational number that maps ref_time to fees, and neither can be zero.

Accept Ethereum Transactions

The eth-rpc adapter submits Ethereum transactions to the chain through the eth_transact call of pallet-revive. The runtime needs three types to accept them: a transaction extension pipeline that includes SetOrigin, an EthExtra implementation, and the pallet-revive extrinsic type.

  1. Add pallet_revive::evm::tx_extension::SetOrigin to your transaction extension tuple, after all extensions that rely on a signed origin. The Revive dev runtime uses the following pipeline:

    runtime/src/lib.rs
    type TxExtension = (
        frame_system::CheckNonZeroSender<Runtime>,
        frame_system::CheckSpecVersion<Runtime>,
        frame_system::CheckTxVersion<Runtime>,
        frame_system::CheckGenesis<Runtime>,
        frame_system::CheckEra<Runtime>,
        frame_system::CheckNonce<Runtime>,
        frame_system::CheckWeight<Runtime>,
        pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
        // Needs to be done after all extensions that rely on a signed origin.
        pallet_revive::evm::tx_extension::SetOrigin<Runtime>,
        // Must be last to catch the refund in previous transaction extensions.
        frame_system::WeightReclaim<Runtime>,
    );
    
  2. Implement the EthExtra trait. Its get_eth_extension function builds the extension values that the runtime applies to an Ethereum transaction, using the nonce and tip taken from that transaction. Return one value per entry in your TxExtension tuple, in the same order, and construct SetOrigin with new_from_eth_transaction(). The Revive dev runtime's implementation is:

    runtime/src/lib.rs
    use pallet_revive::evm::runtime::EthExtra;
    
    /// Default extensions applied to Ethereum transactions.
    #[derive(Clone, PartialEq, Eq, Debug)]
    pub struct EthExtraImpl;
    
    impl EthExtra for EthExtraImpl {
        type Config = Runtime;
        type ExtensionV0 = TxExtension;
        type ExtensionOtherVersions = sp_runtime::traits::InvalidVersion;
    
        fn get_eth_extension(nonce: u32, tip: Balance) -> Self::ExtensionV0 {
            (
                frame_system::CheckNonZeroSender::<Runtime>::new(),
                frame_system::CheckSpecVersion::<Runtime>::new(),
                frame_system::CheckTxVersion::<Runtime>::new(),
                frame_system::CheckGenesis::<Runtime>::new(),
                frame_system::CheckMortality::from(sp_runtime::generic::Era::Immortal),
                frame_system::CheckNonce::<Runtime>::from(nonce),
                frame_system::CheckWeight::<Runtime>::new(),
                pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip),
                pallet_revive::evm::tx_extension::SetOrigin::<Runtime>::new_from_eth_transaction(),
                frame_system::WeightReclaim::<Runtime>::new(),
            )
        }
    }
    

    The extension must include frame_system::CheckNonce so that the runtime checks the nonce of the Ethereum transaction.

  3. Replace your runtime's UncheckedExtrinsic type with the pallet-revive UncheckedExtrinsic, which wraps the generic extrinsic type and adds support for eth_transact:

    runtime/src/lib.rs
    pub type UncheckedExtrinsic =
        pallet_revive::evm::runtime::UncheckedExtrinsic<Address, Signature, EthExtraImpl>;
    

If your runtime already uses a wrapping extension, such as cumulus_pallet_weight_reclaim::StorageWeightReclaim in a parachain, keep it and add SetOrigin inside the wrapped tuple. The Asset Hub Westend runtime shows this pattern.

Implement the Config Trait

Implement pallet_revive::Config for your runtime. The following implementation combines the kitchensink runtime's deposit parameters and Config implementation, with its precompiles removed. deposit is a helper in the kitchensink runtime that prices storage items and bytes in the native token; use your runtime's equivalent.

runtime/src/lib.rs
parameter_types! {
    pub const DepositPerItem: Balance = deposit(1, 0);
    pub const DepositPerChildTrieItem: Balance = deposit(1, 0) / 100;
    pub const DepositPerByte: Balance = deposit(0, 1);
    pub CodeHashLockupDepositPercent: Perbill = Perbill::from_percent(30);
    pub const MaxEthExtrinsicWeight: FixedU128 = FixedU128::from_rational(9, 10);
}

impl pallet_revive::Config for Runtime {
    type Time = Timestamp;
    type Balance = Balance;
    type Currency = Balances;
    type RuntimeEvent = RuntimeEvent;
    type RuntimeCall = RuntimeCall;
    type RuntimeOrigin = RuntimeOrigin;
    type DepositPerItem = DepositPerItem;
    type DepositPerChildTrieItem = DepositPerChildTrieItem;
    type DepositPerByte = DepositPerByte;
    type WeightInfo = pallet_revive::weights::SubstrateWeight<Self>;
    type Precompiles = ();
    type AddressMapper = pallet_revive::AccountId32Mapper<Self>;
    type RuntimeMemory = ConstU32<{ 128 * 1024 * 1024 }>;
    type PVFMemory = ConstU32<{ 512 * 1024 * 1024 }>;
    type UploadOrigin = EnsureSigned<Self::AccountId>;
    type InstantiateOrigin = EnsureSigned<Self::AccountId>;
    type RuntimeHoldReason = RuntimeHoldReason;
    type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
    type ChainId = ConstU64<420_420_420>;
    type NativeToEthRatio = ConstU32<1_000_000>; // 10^(18 - 12) Eth is 10^18, Native is 10^12.
    type FindAuthor = <Runtime as pallet_authorship::Config>::FindAuthor;
    type AllowEVMBytecode = ConstBool<true>;
    type FeeInfo = pallet_revive::evm::fees::Info<Address, Signature, EthExtraImpl>;
    type MaxEthExtrinsicWeight = MaxEthExtrinsicWeight;
    type DebugEnabled = ConstBool<false>;
    type AutoMap = ConstBool<false>;
    type GasScale = ConstU32<1000>;
    type OnBurn = ();
    type Deposit = ();
}

The Config items fall into the following groups. For the full description of each item, see the Config trait source.

  • Runtime types: RuntimeEvent, RuntimeCall, RuntimeOrigin, and RuntimeHoldReason link the pallet to the runtime's aggregated types.
  • Currency and time: Currency is the fungible token that pays fees and holds contract balances, Balance is its balance type, and Time supplies timestamps to contracts.
  • Storage deposits: DepositPerByte, DepositPerItem, and DepositPerChildTrieItem set what callers pay for storage. CodeHashLockupDepositPercent sets the share of the code deposit held when a contract is instantiated from a code hash. Deposit selects the payment backend for deposits; () always uses the native currency.
  • Ethereum compatibility: ChainId is the chain ID reported to Ethereum tools. NativeToEthRatio is the ratio between the decimal representation of the native token and ETH's 18 decimals. FeeInfo must be pallet_revive::evm::fees::Info in a production runtime. AddressMapper maps between native accounts and Ethereum addresses, and must be AccountId32Mapper or H160Mapper.
  • Gas and weight: GasScale scales the gas price and gas estimates, so that gas costs are closer to standard EVM values, and cannot be 0. MaxEthExtrinsicWeight caps the weight of eth_transact extrinsics as a fraction of the maximum extrinsic weight.
  • Code and origins: AllowEVMBytecode allows EVM bytecode to be uploaded and instantiated, in addition to PVM bytecode. UploadOrigin and InstantiateOrigin control who can upload and instantiate contracts; EnsureSigned allows anyone.
  • Memory: RuntimeMemory and PVFMemory are the memory available to the runtime and to the PoV validation function. The pallet's integrity test uses them to check that the runtime has enough memory.
  • Other: Precompiles registers additional precompiles, FindAuthor finds the block author, WeightInfo provides benchmarked weights, OnBurn receives native currency burned through gas rounding, DebugEnabled enables debug settings such as unlimited contract size, and AutoMap enables automatic account mapping.

The Asset Hub Westend runtime differs from this configuration in several items. For example, it registers asset, XCM, asset conversion, and vesting precompiles, sets AutoMap to true, and uses a different chain ID. See its Config implementation.

Note

The Revive dev runtime uses #[derive_impl(pallet_revive::config_preludes::TestDefaultConfig)] to fill in most items. That prelude provides default configurations for testing environments, for example, WeightInfo = () and FeeInfo = (). Set every item explicitly in a production runtime, as the kitchensink and Asset Hub Westend runtimes do.

Set the Chain ID

ChainId is the EIP-155 chain ID, which identifies your chain to Ethereum wallets and tools and prevents transactions signed for one chain from being replayed on another. The eth-rpc adapter reads this value from the runtime and returns it for eth_chainId.

Choose a value that no other network uses. The reference runtimes use 420_420_420 (kitchensink and Revive dev runtime) and 420_420_421 (Asset Hub Westend), so do not reuse those values for your own network.

Enable Automatic Account Mapping

Native AccountId32 accounts must be mapped to Ethereum addresses before they can interact with contracts. By default, accounts map themselves with the map_account call. If you set AutoMap to true, the pallet maps accounts automatically when they are created and unmaps them when they are removed, and disables the map_account and unmap_account calls.

AutoMap requires you to set pallet_revive::AutoMapper as the account creation and removal hooks in frame_system::Config. The Revive dev runtime does this:

runtime/src/lib.rs
impl frame_system::Config for Runtime {
    // ... other configuration
    type OnNewAccount = pallet_revive::AutoMapper<Runtime>;
    type OnKilledAccount = pallet_revive::AutoMapper<Runtime>;
}

Add the Pallet to the Runtime

Add pallet-revive to your runtime under the name Revive. The runtime API macro in the next section takes this name as a parameter, and the eth-rpc adapter's client looks up the pallet's constants by it.

The Revive dev runtime declares the pallet as follows. Use a pallet index that is unused in your runtime.

runtime/src/lib.rs
#[runtime::pallet_index(5)]
pub type Revive = pallet_revive::Pallet<Runtime>;

The Asset Hub Westend runtime declares the pallet as follows. Use a pallet index that is unused in your runtime.

runtime/src/lib.rs
construct_runtime!(
    pub enum Runtime {
        // ... other pallets
        Revive: pallet_revive = 60,
    }
);

Implement the Runtime APIs

The eth-rpc adapter calls the ReviveApi runtime API for balances, nonces, calls, gas estimation, gas price, block information, and tracing. pallet-revive provides the impl_runtime_apis_plus_revive_traits! macro, which wraps impl_runtime_apis!, implements ReviveApi, and implements the SetWeightLimit trait for the runtime call type.

Replace impl_runtime_apis! with this macro and pass four parameters before your existing runtime API implementations:

  • Runtime: The runtime type.
  • Revive: The name under which the pallet is declared in the runtime.
  • Executive: The runtime's Executive type.
  • EthExtraImpl: Your EthExtra implementation.

The Revive dev runtime uses it as follows:

runtime/src/apis.rs
pallet_revive::impl_runtime_apis_plus_revive_traits!(
    Runtime,
    Revive,
    Executive,
    EthExtraImpl,

    impl apis::Core<Block> for Runtime {
        fn version() -> RuntimeVersion {
            VERSION
        }
        // ... other functions
    }

    // ... other runtime API implementations
);

Keep all the runtime API implementations you already have inside the macro call; do not implement ReviveApi yourself.

Register Precompiles

pallet-revive includes the standard Ethereum precompiles and its own system precompiles. To expose more runtime functionality to contracts, pass a tuple of types that implement the Precompile trait to Config::Precompiles. The type is usually provided by another pallet. To write your own, see Write a Custom Precompile.

For example, the kitchensink runtime registers ERC-20 precompiles for two instances of the Assets pallet and a vesting precompile:

runtime/src/lib.rs
use pallet_assets_precompiles::{InlineIdConfig, ERC20};
use pallet_vesting_precompiles::Vesting as VestingPrecompile;

impl pallet_revive::Config for Runtime {
    // ... other configuration
    type Precompiles = (
        ERC20<Self, InlineIdConfig<0x1>, Instance1>,
        ERC20<Self, InlineIdConfig<0x2>, Instance2>,
        VestingPrecompile<Self>,
    );
}

Each precompile crate is a separate dependency of your runtime, and some, such as the vesting precompile, also require their own pallet in the runtime. The Asset Hub Westend runtime additionally registers pallet_xcm_precompiles::XcmPrecompile and the asset conversion precompile. For the precompiles that contracts can call, see Precompiles.

Configure Genesis

The pallet-revive genesis configuration has a mapped_accounts field that lists native accounts to map at genesis, so they can interact with contracts from the first block. The Revive dev runtime's development preset maps its endowed accounts:

runtime/src/genesis_config_presets.rs
revive: ReviveConfig {
    mapped_accounts: endowed_accounts
        .iter()
        .filter(|x| !<Runtime as pallet_revive::Config>::AddressMapper::is_mapped(x))
        .cloned()
        .collect(),
},

Verify the Integration

  1. Build your runtime and node, then start the node locally with its development configuration.
  2. Build and start the eth-rpc adapter against your node, as described in Run the Ethereum JSON-RPC Adapter.
  3. Request the chain ID through the adapter:

    curl -s -X POST http://127.0.0.1:8545 \
      -H "Content-Type: application/json" \
      -d '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}'
    

    The result is your ChainId value in hexadecimal. If the adapter fails to start, check its logs for missing runtime APIs or constants.

Where to Go Next

  • Guide Run the Ethereum JSON-RPC Adapter


    Build, run, and configure the eth-rpc adapter next to your node.

    Get Started

  • Learn Smart Contracts Overview


    Learn how pallet-revive, its execution backends, and its tooling fit together.

    Learn More

Last update: November 17, 2026
| Created: November 17, 2026