Skip to Content

Address Precompile

Address: 0x0000000000000000000000000000000000001004

The Sei Address precompile allows EVM applications to interact directly with Sei’s address association system through standard smart contract calls. This enables querying and creating mappings between EVM addresses and their corresponding Cosmos addresses, enabling seamless cross-chain address management without needing separate Cosmos SDK integration.

What is a precompile? A precompile is a special smart contract deployed at a fixed address by the Sei protocol itself, that exposes custom native chain logic to EVM-based applications. It acts like a regular contract from the EVM’s perspective, but executes privileged, low-level logic efficiently.

How Does the Address Precompile Work?

The Address precompile at address 0x0000000000000000000000000000000000001004 exposes functions like associate(), associatePubKey(), getSeiAddr(), and getEvmAddr().

  • Direct Integration: EVM contracts and dApps can call address association functions like any other smart contract method.
  • Native Execution: Operations are executed at the Cosmos SDK level for maximum efficiency and security.
  • Seamless Bridge: No need for separate wallet integrations or complex cross-chain interactions.

Use Cases

  • Cross-Chain Identity: Link EVM and Cosmos addresses for unified user experiences across both execution environments.
  • Address Resolution: Build applications that can seamlessly work with both EVM and Cosmos address formats.
  • Wallet Integration: Enable users to associate their addresses once and use both EVM and native Sei functionality.
  • DeFi Applications: Create protocols that can interact with users regardless of their preferred address format.

What You’ll Learn in This Guide

By the end of this guide, you’ll be able to:

  • Integrate Address Operations - Call association and lookup functions directly from your EVM contracts and dApps
  • Handle Signature Verification - Master the signature format requirements for secure address association
  • Manage Address Mappings - Query and validate address relationships between EVM and Cosmos formats
  • Build Cross-Chain Tools - Implement unified address management for applications spanning both execution environments
  • Navigate Association Requirements - Understand when and how address association occurs automatically vs. manually

Functions

The Address precompile exposes the following functions:

Transaction Functions

/// Associates an account given it's signature of any custom message. /// @param v The v component of the signature. /// @param r The r component of the signature. /// @param s The s component of the signature. /// @param customMessage A custom message that was signed by the address to be associated. /// @return seiAddr The associated Sei address. /// @return evmAddr The associated EVM address. function associate( string memory v, string memory r, string memory s, string memory customMessage ) external returns (string memory seiAddr, address evmAddr); /// Associates an account given it's compressed pubkey in hex format (excluding the '0x') /// @param pubKeyHex The Hex-encoded compressed pubkey of the account to be associated, excluding the '0x' /// @return seiAddr The associated Sei address. /// @return evmAddr The associated EVM address. function associatePubKey( string memory pubKeyHex ) external returns (string memory seiAddr, address evmAddr);

Query Functions

/// Queries the corresponding Sei Address for some EVM address. /// @param addr The EVM Address for which we want the corresponding Sei address. /// @return response The corresponding Sei address. function getSeiAddr( address addr ) external view returns (string memory response); /// Queries the corresponding EVM Address for some Sei address. /// @param addr The Sei Address for which we want the corresponding EVM address. /// @return response The corresponding EVM address. function getEvmAddr( string memory addr ) external view returns (address response);

Using the Precompile

Setup

Prerequisites

Before getting started, ensure you have:

  • Node.js (v16 or higher)
  • npm or yarn package manager
  • EVM-compatible wallet
  • SEI tokens for gas fees
  • Hardhat development environment set up

Install Dependencies

Install the required packages for interacting with Sei precompiles:

# Intitate a hardhat project npx hardhat init # Install ethers.js for smart contract interactions npm install ethers dotenv # Install Sei EVM bindings for precompile addresses and ABIs npm install @sei-js/precompiles@2.1.2

Setup Hardhat Environment

Create a hardhat.config.js file with the following content:

require('@nomicfoundation/hardhat-toolbox'); require('dotenv').config(); /** @type import('hardhat/config').HardhatUserConfig */ module.exports = { solidity: '0.8.28', networks: { sei: { url: 'https://evm-rpc.sei-apis.com', chainId: 1329, accounts: [process.env.PRIVATE_KEY] } } };

Create a .env file in the root directory with your private key and RPC URL:

PRIVATE_KEY=your_private_key_here RPC_URL=https://evm-rpc.sei-apis.com

Import Precompile Components

// Import Address precompile address and ABI // View the entire ABI here: https://github.com/sei-protocol/sei-chain/tree/main/precompiles/addr import { ADDRESS_PRECOMPILE_ABI, ADDRESS_PRECOMPILE_ADDRESS } from '@sei-js/precompiles'; import { ethers } from 'ethers';
Precompile Address: The address precompile is deployed at 0x0000000000000000000000000000000000001004

Contract Initialization

Set up your provider, signer, and contract instance:

// Using EVM-compatible wallet as the signer and provider const provider = new ethers.BrowserProvider(window.ethereum); await provider.send('eth_requestAccounts', []); const signer = await provider.getSigner(); // Create a contract instance for the addr precompile const addr = new ethers.Contract(ADDRESS_PRECOMPILE_ADDRESS, ADDRESS_PRECOMPILE_ABI, signer);

When Does Association Happen?

Address association between EVM and Cosmos addresses occurs automatically in most cases:

MethodTriggerRequirements
AutomaticFirst transaction broadcastWallet signs any transaction
Manual (Signature)associate() functionCustom message signature
Manual (PubKey)associatePubKey() functionCompressed public key

How Association Works

Automatic Association:

  • Occurs when a wallet first signs and broadcasts any transaction on Sei
  • No additional steps required for most users
  • Association is permanent once created

Manual Association:

  • Use associate() for signature-based association
  • Use associatePubKey() for public key-based association
  • Useful for advanced applications or when automatic association hasn’t occurred

Address Format Requirements

EVM Addresses:

  • Standard Ethereum format: 0x1234... (20 bytes, 40 hex characters)
  • Case-insensitive but typically lowercase

Sei Addresses:

  • Cosmos format with sei1... prefix for regular addresses
  • Validator addresses use seivaloper1... prefix
  • Bech32 encoding format

Step-by-Step Guide: Using the Address Precompile

Associate Address with Signature

// Associate addresses using a custom message signature const message = `Associate my addresses - ${Date.now()}`; try { // Get signature from user's wallet const signature = await signer.signMessage(message); const sig = ethers.Signature.from(signature); // Prepare the prefixed message (signMessage already applies this prefix) const messageBytes = new TextEncoder().encode(message); const customMessage = `\x19Ethereum Signed Message:\n${message}`; // Convert signature components to strings const v = (sig.v - 27).toString(); const r = sig.r; const s = sig.s; // Call associate function const tx = await addr.associate(v, r, s, customMessage); const receipt = await tx.wait(); console.log('Association successful:', receipt); } catch (error) { console.error('Association failed:', error); }

Associate Address with Public Key

// Associate addresses using a public key try { // Create or get a wallet's public key const wallet = ethers.Wallet.createRandom(); const pubKeyWithout0x = wallet.signingKey.compressedPublicKey.slice(2); // Call associatePubKey function const tx = await addr.associatePubKey(pubKeyWithout0x); const receipt = await tx.wait(); console.log('Public key association successful:', receipt); } catch (error) { console.error('Public key association failed:', error); }

Query Sei Address from EVM Address

// Query the Sei address for a given EVM address const evmAddress = '0x1234567890123456789012345678901234567890'; try { const seiAddress = await addr.getSeiAddr(evmAddress); console.log('Corresponding Sei address:', seiAddress); } catch (error) { if (error.message.includes('not found') || error.message.includes('no association')) { console.log('No association found for this EVM address'); } else { console.error('Error querying Sei address:', error); } }

Query EVM Address from Sei Address

// Query the EVM address for a given Sei address const seiAddress = 'sei1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq6s8dpw'; try { const evmAddress = await addr.getEvmAddr(seiAddress); console.log('Corresponding EVM address:', evmAddress); } catch (error) { if (error.message.includes('not found') || error.message.includes('no association')) { console.log('No association found for this Sei address'); } else { console.error('Error querying EVM address:', error); } }

Complete Integration Example

import { ADDRESS_PRECOMPILE_ABI, ADDRESS_PRECOMPILE_ADDRESS } from '@sei-js/precompiles'; import { ethers } from 'ethers'; async function addrExample() { // Setup const provider = new ethers.BrowserProvider(window.ethereum); await provider.send('eth_requestAccounts', []); const signer = await provider.getSigner(); const addr = new ethers.Contract(ADDRESS_PRECOMPILE_ADDRESS, ADDRESS_PRECOMPILE_ABI, signer); const evmAddress = await signer.getAddress(); try { // 1. Check if current EVM address has an associated Sei address console.log('=== Checking Current Association ==='); try { const associatedSei = await addr.getSeiAddr(evmAddress); console.log('EVM address:', evmAddress); console.log('Associated Sei address:', associatedSei); // Verify reverse lookup const reverseEvm = await addr.getEvmAddr(associatedSei); console.log('Reverse lookup EVM address:', reverseEvm); } catch (error) { if (error.message.includes('not found') || error.message.includes('no association')) { console.log('No association found. You may need to make a transaction first or associate manually.'); // 2. Demonstrate manual association with public key console.log('=== Creating Manual Association ==='); const wallet = ethers.Wallet.createRandom(); const pubKeyWithout0x = wallet.signingKey.compressedPublicKey.slice(2); const associateTx = await addr.associatePubKey(pubKeyWithout0x); const receipt = await associateTx.wait(); console.log('Manual association completed:', receipt.transactionHash); } else { throw error; } } // 3. Demonstrate address resolution for different formats console.log('=== Address Resolution Examples ==='); // Test with known Sei address format const testSeiAddr = 'sei1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq6s8dpw'; try { const correspondingEvm = await addr.getEvmAddr(testSeiAddr); console.log('Test Sei address:', testSeiAddr); console.log('Corresponding EVM address:', correspondingEvm); } catch (error) { console.log('Test address not associated:', testSeiAddr); } } catch (error) { console.error('Operation failed:', error); } }

Security Considerations & Risks

Association Permanence

  • Permanent Mapping: Once addresses are associated, the mapping cannot be changed or removed
  • Single Association: Each address can only be associated with one counterpart
  • Verification: Always verify associations before depending on them in critical operations

Signature Security

  • Custom Messages: Use unique, timestamped messages to prevent replay attacks
  • Message Format: Follow exact Ethereum Signed Message format for compatibility

Troubleshooting

Common Issues and Solutions

// Set appropriate gas limits for different operations const associateTx = await addr.associate(v, r, s, customMessage, { gasLimit: 200000 // Association operations }); const pubKeyTx = await addr.associatePubKey(pubKeyHex, { gasLimit: 150000 // Public key association });

Error Code Reference

ErrorCauseSolution
invalid signatureMalformed v, r, s componentsVerify signature parsing and format
already associatedAddress already has associationCheck existing association instead
not foundNo association existsCreate association first
invalid public keyMalformed public key formatUse compressed format without 0x prefix
invalid address formatWrong address formatUse proper EVM (0x…) or Sei (sei1…) format

Important Notes

Remember: Address associations are permanent and cannot be changed once created!

Address Formats

  • EVM Addresses: Use standard Ethereum format with 0x prefix
  • Sei Addresses: Use Cosmos format with sei1 prefix for regular addresses
  • Case Sensitivity: EVM addresses are case-insensitive, Sei addresses are case-sensitive

Association Timing

  • Automatic: Most users get associated automatically on their first transaction
  • Manual: Use precompile functions for programmatic association or when automatic association hasn’t occurred
  • Verification: Always verify associations exist before depending on them

Signature Requirements

  • Message Format: Must include Ethereum Signed Message prefix for associate() function
  • Component Format: v, r, s must be properly formatted hex strings
  • Replay Protection: Use unique messages to prevent signature replay attacks

Gas Considerations

  • Association operations: ~200,000 gas limit recommended
  • Query operations: Standard view function gas usage
  • Batch operations: Scale gas limits based on array size
View the Address precompile source code and the contract ABI here.
Last updated on