npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sei-js/evm

v1.4.1

Published

TypeScript library for EVM interactions on the Sei blockchain

Downloads

716

Readme

@sei-js/evm

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

Installation

yarn add @sei-js/evm

Wallet Connection

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.

Wallet network setup

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

Connection with Wagmi

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>
 );
};

Connection with ethers v6

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]);

Usage with viem

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.

Utils

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

parseSei

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

Interoperability with Cosmos

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. |

Interoperability using Wagmi, viem, and ethers

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.

Address Precompile

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

Functions

| 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'). |

Precompile Address

0x0000000000000000000000000000000000001004

Bank Precompile

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

Functions

| 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. |

Precompile Addresses

0x0000000000000000000000000000000000001001

Distribution Precompile

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

Functions

| 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. |

Precompile Addresses

0x0000000000000000000000000000000000001007

Governance Precompile

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

Functions

| 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. |

Precompile Addresses

0x0000000000000000000000000000000000001006

JSON Precompile

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

Functions

| 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. |

Precompile Addresses

Staking Precompile

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

Functions

| 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. |

Precompile Addresses

0x0000000000000000000000000000000000001005

WASM Precompile

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

Functions

| 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. |

Precompile Addresses

0x0000000000000000000000000000000000001002

IBC Precompile

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

Functions

| 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 |

Precompile Addresses

0x0000000000000000000000000000000000001009