Module evm

@sei-js/evm

Typescript library containing helper functions for interacting with the EVM on Sei.

yarn add @sei-js/evm ethers viem


This package provides exports for easily interacting with wagmi, viem, and ethers.js. You can interact with the Sei EVM using all the same hooks and helper functions these tools offer. Read the Wagmi, viem, and ethers v6 documentation for more information on how to use these tools.

Ensure that your EVM wallet has the Sei network enabled. Learn more on how to set up your wallet.


The WagmiProvider is a React context provider that allows you to easily interact with the EVM. It provides many useful hooks for reading and writing on Sei via the EVM JSON-RPC.

import { ReactNode } from 'react';
import { WagmiProvider } from 'wagmi';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ARCTIC_1_VIEM_CHAIN, createWagmiConfig } from '@sei-js/evm';

const queryClient = new QueryClient();

export const WalletProvider = ({ children }: { children: ReactNode }) => {
return (
<WagmiProvider config={createWagmiConfig([ARCTIC_1_VIEM_CHAIN])}>
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
</WagmiProvider>
);
};

The 'ethers' package is a popular library for interacting with the Ethereum blockchain. This package provides a helper function for creating an ethers provider that is connected to the Sei EVM.

import { ADDRESS_PRECOMPILE_ADDRESS } from '@sei-js/evm';
import { ethers } from 'ethers';

const provider = new ethers.BrowserProvider(window.ethereum); // or any other provider
const signer = await provider.getSigner();

const accounts = await provider.send('eth_requestAccounts', []);

const contract = getAddressPrecompileEthersV6Contract(ADDRESS_PRECOMPILE_ADDRESS, signer);

const cosmosAddress = await contract.getSeiAddr(accounts[0]);

This package exports viem Chains and precompile ABI's for Sei. The ABI used in the ethers example above is a viem ABI instance and the ARCTIC_1_VIEM_CHAIN is a viem Chain instance.



This package also exports a set of utility functions for interacting with the EVM on Sei.

Parses an amount of Sei to the smallest unit of Sei (uSei).

import { parseSei } from '@sei-js/evm';

const amount = parseSei('1000000');
console.log(amount); // 1000000000000000000


Sei v2 supports both EVM JSON-RPC and Cosmos RPC interfaces. In order to easily interact with certain Cosmos modules, Sei v2 has a set of precompiled contracts that can be called from the EVM.

Precompile Description
Address Precompile Enables the retrieval of associated EVM addresses for given Cosmos addresses and vice versa.
Bank Precompile Provides functionalities for managing balances, supply, symbols, and more.
Distribution Precompile Facilitates operations related to rewards withdrawal and distribution.
Governance Precompile Supports actions such as depositing funds into proposals and voting.
JSON Precompile Facilitates interoperability between the EVM and Cosmos.
Staking Precompile Enables staking functionalities like delegation and undelegation.
WASM Precompile Provides functionalities for executing WebAssembly (WASM) code.

Each precompile has contract exports a typed 'ethers' contracts and provides the ABI and contract addresses for each precompile for usage with Wagmi and viem.



The Address precompile contract enables the retrieval of associated EVM addresses for given Cosmos addresses and vice versa.

Function Name Input Parameters Return Value Description
getEvmAddr addr: string { response: string } Retrieves the associated EVM address for a given Cosmos address.
getSeiAddr addr: string { response: string } Retrieves the associated Cosmos address for a given EVM address.
associate v: string, r: string, s: string, customMessage: string { response: string } Associates an EVM address with it's corresponding Sei Native address on chain using a signature.
associatePubKey pubKeyHex: string { response: string } Associates an EVM address with it's corresponding Cosmos address on chain using the Hex-Encoded compressed pubkey (excluding the '0x').

0x0000000000000000000000000000000000001004



The Bank precompile contract provides functionalities for managing balances, supply, symbols, and more.

Function Name Input Parameters Return Value Description
balance acc: string, denom: string { amount: string } Retrieves the balance of the specified account for the given denomination.
decimals denom: string { response: string } Retrieves the number of decimal places for the specified denomination.
name denom: string { response: string } Retrieves the name of the specified denomination.
send fromAddress: string, toAddress: string, denom: string, amount: number { success: boolean } Sends tokens from one address to another.
supply denom: string { response: string } Retrieves the total supply of tokens for the specified denomination.
symbol denom: string { response: string } Retrieves the symbol of the specified denomination.
sendNative toNativeAddress: string, value: string { success: boolean } Sends native tokens to a specified address.

0x0000000000000000000000000000000000001001



The Distribution precompile contract facilitates operations related to rewards withdrawal and distribution.

Function Name Input Parameters Return Value Description
setWithdrawAddress withdrawAddress: string { success: boolean } Sets the withdrawal address for rewards.
withdrawDelegationRewards validator: string { success: boolean } Withdraws delegation rewards for a given validator.
withdrawMultipleDelegationRewards validators: string[] { success: boolean } Withdraws delegation rewards for given validators.
rewards delegatorAddress: address { rewards: Rewards } Queries rewards available for a given delegator address. Rewards are usually returned as decimals. To calculate the actual amount, divide the amount by decimals.

0x0000000000000000000000000000000000001007



The Governance precompile contract supports actions to deposit funds into proposals and vote on them.

Function Name Input Parameters Return Value Description
deposit proposalID: string { success: boolean } Deposits funds into a governance proposal.
vote proposalID: string, option: string { success: boolean } Votes on a governance proposal.

0x0000000000000000000000000000000000001006



The JSON precompile contract facilitates interoperability between the EVM and Cosmos by providing functions to extract data in various formats.

Function Name Input Parameters Return Value Description
extractAsBytes input: string, key: string { response: string } Extracts data as bytes from the input using the specified key.
extractAsBytesList input: string, key: string { response: string[] } Extracts data as a list of bytes from the input using the specified key.
extractAsUint256 input: string, key: string { response: string } Extracts data as a uint256 from the input using the specified key.


The Staking precompile contract provides functions for delegation, re-delegation, and un-delegation staking operations.

Function Name Input Parameters Return Value Description
delegate valAddress: string { success: boolean } Delegates tokens to the specified validator.
redelegate srcAddress: string, dstAddress: string, amount: string { success: boolean } Redelegates tokens from the source validator to the destination validator.
undelegate valAddress: string, amount: string { success: boolean } Undelegates tokens from the specified validator.
delegation delegator: address, valAddress: string { delegation: Delegation } Queries delegation by delegator and validator address. Shares in DelegationDetails are usually returned as decimals. To calculate the actual amount, divide the shares by decimals.

0x0000000000000000000000000000000000001005



The WASM precompile contract facilitates execution, instantiation, and querying of WebAssembly (WASM) contracts on the Sei platform.

Function Name Input Parameters Return Value Description
execute contractAddress: string, msg: Uint8Array, coins: Uint8Array { response: Uint8Array } Executes a message on the specified contract with provided coins.
instantiate codeID: string, admin: string, msg: Uint8Array, label: string, coins: Uint8Array { contractAddr: string; data: Uint8Array } Instantiates a new contract with the specified code ID, admin, and coins.
query contractAddress: string, req: Uint8Array { response: Uint8Array } Queries the specified contract with the provided request.

0x0000000000000000000000000000000000001002



The IBC precompile contract facilitates messages exchange between Sei and other IBC compatible blockchains.

Function Name Input Parameters Return Value Description
transfer toAddress: string, port: string, channel: string, denom: string, amount: ethers.BigNumberish, revisionNumber: BigInt, revisionHeight: BigInt, timeoutTimestamp: BigInt, memo: String { success: boolean } Transfers tokens from the caller's address to another on a different (IBC compatible) chain.
transferWithDefaultTimeout toAddress: string, port: string, channel: string, denom: string, amount: ethers.BigNumberish, memo: String { success: boolean } Transfers tokens from the caller's address to another on a different (IBC compatible) chain. Calculates default timeout height as opposed to transfer function

0x0000000000000000000000000000000000001009

Cosmos Interoperability

ADDRESS_PRECOMPILE_ABI
ADDRESS_PRECOMPILE_ADDRESS
BANK_PRECOMPILE_ABI
BANK_PRECOMPILE_ADDRESS
DISTRIBUTION_PRECOMPILE_ABI
DISTRIBUTION_PRECOMPILE_ADDRESS
ETHERS_ADDRESS_PRECOMPILE_ABI
ETHERS_BANK_PRECOMPILE_ABI
ETHERS_DISTRIBUTION_PRECOMPILE_ABI
ETHERS_GOVERNANCE_PRECOMPILE_ABI
ETHERS_IBC_PRECOMPILE_ABI
ETHERS_JSON_PRECOMPILE_ABI
ETHERS_ORACLE_PRECOMPILE_ABI
ETHERS_POINTER_PRECOMPILE_ABI
ETHERS_POINTERVIEW_PRECOMPILE_ABI
ETHERS_STAKING_PRECOMPILE_ABI
ETHERS_WASM_PRECOMPILE_ABI
GOVERNANCE_PRECOMPILE_ABI
GOVERNANCE_PRECOMPILE_ADDRESS
IBC_PRECOMPILE_ABI
IBC_PRECOMPILE_ADDRESS
JSON_PRECOMPILE_ABI
JSON_PRECOMPILE_ADDRESS
ORACLE_PRECOMPILE_ABI
ORACLE_PRECOMPILE_ADDRESS
POINTER_PRECOMPILE_ABI
POINTER_PRECOMPILE_ADDRESS
POINTERVIEW_PRECOMPILE_ABI
POINTERVIEW_PRECOMPILE_ADDRESS
STAKING_PRECOMPILE_ABI
STAKING_PRECOMPILE_ADDRESS
VIEM_ADDRESS_PRECOMPILE_ABI
VIEM_BANK_PRECOMPILE_ABI
VIEM_DISTRIBUTION_PRECOMPILE_ABI
VIEM_GOVERNANCE_PRECOMPILE_ABI
VIEM_IBC_PRECOMPILE_ABI
VIEM_JSON_PRECOMPILE_ABI
VIEM_ORACLE_PRECOMPILE_ABI
VIEM_POINTER_PRECOMPILE_ABI
VIEM_POINTERVIEW_PRECOMPILE_ABI
VIEM_STAKING_PRECOMPILE_ABI
VIEM_WASM_PRECOMPILE_ABI
WASM_PRECOMPILE_ABI
WASM_PRECOMPILE_ADDRESS
getAddressPrecompileEthersV6Contract
getBankPrecompileEthersV6Contract
getDistributionPrecompileEthersV6Contract
getGovernancePrecompileEthersV6Contract
getIbcPrecompileEthersV6Contract
getJSONPrecompileEthersV6Contract
getOraclePrecompileEthersV6Contract
getPointerPrecompileEthersV6Contract
getPointerviewPrecompileEthersV6Contract
getStakingPrecompileEthersV6Contract
getWasmPrecompileEthersV6Contract

Other

seiLocal