Sei provides an Address Precompile at 0x0000000000000000000000000000000000001004
specifically for managing the link between Sei Native (sei1...
) and EVM (0x...
) addresses derived from the same private key.
Key Functions (Solidity Interface):
interface ISeiAddressPrecompile {
// --- View Functions ---
/**
* @notice Gets the associated Sei Bech32 address for a given EVM address.
* @param evmAddr The EVM address (`0x...`) to look up.
* @return seiAddr The associated Sei address string (`sei1...`). Reverts if not associated.
*/
function getSeiAddr(address evmAddr) external view returns (string memory seiAddr);
/**
* @notice Gets the associated EVM address for a given Sei Bech32 address.
* @param seiAddr The Sei address string (`sei1...`) to look up.
* @return evmAddr The associated EVM address (`0x...`). Reverts if not associated.
*/
function getEvmAddr(string memory seiAddr) external view returns (address evmAddr);
// --- State Changing Functions ---
/**
* @notice Associates the EVM and Sei addresses derived from the signer of the provided message.
* @dev Requires a signature created off-chain over the customMessage.
* @param v The recovery ID (usually 27 or 28, potentially as hex string "0x1b" or "0x1c").
* @param r The R component of the ECDSA signature (as hex string).
* @param s The S component of the ECDSA signature (as hex string).
* @param customMessage The exact message string that was signed.
* @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);
/**
* @notice Associates the EVM and Sei addresses derived from a provided public key.
* @dev The public key must be in compressed format, represented as a hex string without the "0x" prefix.
* @param pubKeyHex The compressed public key hex string.
* @return seiAddr The associated Sei address.
* @return evmAddr The associated EVM address.
*/
function associatePubKey(string memory pubKeyHex) external returns (string memory seiAddr, address evmAddr);
}
How to Use:
- Lookups (
getSeiAddr
,getEvmAddr
): Call these view functions directly from your contract to find an existing association. Handle potential reverts if no association exists (e.g., usingtry/catch
). - Association (
associate
,associatePubKey
): These functions create the on-chain link. They are typically not called directly by end-users from a generic contract.- The
associate
function requires an off-chain signature generated by the user's wallet, making it suitable for integration into dApp frontends or dedicated association tools. - The
associatePubKey
function requires the user's compressed public key, which might be less common for users to handle directly. - These functions will fail if an association already exists for the derived addresses.
- The
Important Considerations:
- Association Requirement: Many other Sei precompiles (like Staking, IBC, Bank
send
) require thecaller
to be associated before they can be used successfully. - Gas Costs: Lookup functions are cheap. Association functions (
associate
,associatePubKey
) have a higher base gas cost (e.g., 50,000) due to cryptographic operations. - Security: Association proves ownership. The
associate
function relies on cryptographic signatures for security.
Comments
0 comments
Article is closed for comments.