evm-sdk
v1.0.9
Published
A comprehensive Ethereum Virtual Machine SDK for blockchain interactions, specifically designed for stake, unstake, and withdraw operations from NEAR to BSC.
Readme
EVM SDK
A comprehensive Ethereum Virtual Machine SDK for blockchain interactions, specifically designed for stake, unstake, and withdraw operations from NEAR to BSC.
Features
- 🚀 Easy to Use: Simple and intuitive API design
- 🔒 Type Safe: Full TypeScript support with comprehensive type definitions
- 📦 Lightweight: Minimal dependencies, optimized bundle size
- 🔧 Flexible: Support for multiple networks and configurations
- 📚 Well Documented: Comprehensive documentation and examples
- 🌉 Cross-Chain: Built-in support for NEAR to BSC bridge operations
Installation
npm install evm-sdkor
yarn add evm-sdkProject Structure
evm-sdk/
├── src/ # Source code directory
│ ├── config/ # Configuration files
│ │ ├── bridge.ts # Bridge configuration
│ │ ├── config.ts # Main configuration
│ │ └── rpc.ts # RPC configuration
│ ├── handlers/ # Business logic handlers
│ │ ├── stake.ts # Stake operation handler
│ │ ├── withdraw.ts # Withdraw operation handler
│ │ └── unstake.ts # Unstake operation handler
│ ├── interfaces/ # TypeScript interfaces
│ │ ├── stakeInter.ts # Stake related interfaces
│ │ ├── withdrawInter.ts # Withdraw related interfaces
│ │ └── unstakeInter.ts # Unstake related interfaces
│ ├── services/ # Core services
│ │ └── wormhole.ts # Wormhole bridge service
│ ├── utils/ # Utility functions
│ │ ├── bridgeUtils.ts # Bridge utility functions
│ │ ├── helpers.ts # General helper functions
│ │ └── numbers.ts # Number manipulation utilities
│ ├── types/ # Type definitions
│ │ ├── common.ts # Common type definitions
│ │ └── global.d.ts # Global type declarations
│ └── index.ts # Main entry point
├── dist/ # Build output directory
├── .eslintrc.js # ESLint configuration
├── .prettierrc # Prettier configuration
├── .gitignore # git ignore file
├── package.json # Package configuration
├── tsconfig.json # TypeScript configuration
└── README.md # Project documentationKey Components
src/config/- Configuration files for different environments and chainssrc/handlers/- Business logic handlers for stake/unstake operationssrc/interfaces/- TypeScript interface definitions for type safetysrc/services/- Core services including Wormhole bridge integrationsrc/utils/- Utility functions for common operationssrc/types/- Type definitions and global type declarations
Quick Start
import EVMSDK, {
TokenMeta,
StakeInfo,
StakeParams,
StakeResult,
CreateTxMessage,
StakeMessage,
UnstakeParams,
UnstakeResult,
UnstakeMessage,
WithdrawParams,
WithdrawResult
} from 'evm-sdk' ;
// Initialize the SDK
const BscStake = new EVMSDK();Methods
stake(params: StakeParams): Promise<StakeResult | Error>unstake(params:UnstakeParams): Promise<UnstakeResult | Error>withdraw(params:WithdrawParams): Promise<WithdrawResult | Error>queryNearAccountByEvmAccount(evmAccount:string): nearAccountIdgetCreateFee(nearAccount:string)getTokenBridgeFee(nearAccount:string)
new account tips
If you are a new account on NEAR, you need to use getCreateFee() and getTokenBridgeFee() to get your required fees, and ensure you meet the minimum stake amount.
How To Use
const stakeRes = await stake({
waitStakeTokenID: RHEA_TOKEN_ID_NEAR,
stakedXTokenID: XRHEA_TOKEN_ID_NEAR,
nearAccountId: '',
signer: await window.ethWeb3Provider?.getSigner(),
env: 'production',
rpcUrl: 'https://free.rpc.fastnear.com',
stakeInfo: {
from: 'BSC',
to: 'NEAR',
amountIn: '1',
sender: BSC_ACOOUNT_ID,
fromTokenMeta: {
address: RHEA_TOKEN_ID_BSC,
symbol: 'RHEA',
decimals: 18,
icon: 'https://xxx.com/token/rhea.svg'
},
toTokenMeta: {
address: RHEA_TOKEN_ID_NEAR;
symbol: 'RHEA';
decimals: 18;
icon: 'https://xxx.com/token/rhea.svg';
}
}
})
const UnStakeRes = await unstake({
waitUnstakeXTokenID: XRHEA_TOKEN_ID_NEAR,
unstakedTokenID: RHEA_TOKEN_ID_NEAR,
nearAccountId: '',
signer: await window.ethWeb3Provider?.getSigner(),
env: 'production',
rpcUrl: 'https://free.rpc.fastnear.com',
stakeInfo: {
from: 'BSC',
to: 'NEAR',
amountIn: '1',
sender: BSC_ACOOUNT_ID,
fromTokenMeta: {
address: XRHEA_TOKEN_ID_BSC,
symbol: 'xRHEA',
decimals: 18,
icon: 'https://xxx.com/token/rhea.svg'
},
toTokenMeta: {
address: XRHEA_TOKEN_ID_NEAR;
symbol: 'xRHEA';
decimals: 18;
icon: 'https://xxx.com/token/rhea.svg';
}
}
})
const withdrawRes = await withdraw({
withdrawTokenIDOnNear: RHEA_TOKEN_ID_NEAR || XRHEA_TOKEN_ID_NEAR,
withdrawTokenIDOnBsc: RHEA_TOKEN_ID_BSC || XRHEA_TOKEN_ID_BSC,
receiver: 'xxx.near',
withdrawBalance: '1111',
evmRpcUrl: 'https://bsc.drpc.org',
stakeInfo: {
from: 'BSC',
to: 'NEAR',
amountIn: '1',
sender: BSC_ACOOUNT_ID,
fromTokenMeta: {
address: RHEA_TOKEN_ID_NEAR || XRHEA_TOKEN_ID_NEAR,
symbol: 'RHEA' || 'xRHEA',
decimals: 18,
icon: 'https://xxx.com/token/rhea.svg'
},
toTokenMeta: {
address: RHEA_TOKEN_ID_BSC || XRHEA_TOKEN_ID_BSC,
symbol: 'RHEA' || 'xRHEA',
decimals: 18;
icon: 'https://xxx.com/token/rhea.svg';
}
}
})Types
interface StakeParams {
stakeInfo: StakeInfo | {
from: BridgeModel.BridgeSupportChain;
to: BridgeModel.BridgeSupportChain;
fromTokenMeta: TokenMeta | {
address: string; // such as RHEA id on BSC
symbol: string; //such as RHEA、PublicAI
decimals: number;
icon: string;
};
toTokenMeta: TokenMeta | {
address: string; // such as RHEA id on NEAR
symbol: string;
decimals: number;
icon: string;
};
amountIn: string;
sender: string;
};
waitStakeTokenID: string; // such as RHEA id on NEAR
stakedXTokenID: string; // such as xRHEA id on NEAR
nearAccountId: string | ''; // your near accountId
signer: Signer; // await window.ethWeb3Provider?.getSigner();
env?: string; // production
rpcUrl?: string; // ex: https://free.rpc.fastnear.com
}
interface UnstakeParams {
stakeInfo: StakeInfo | {
from: BridgeModel.BridgeSupportChain;
to: BridgeModel.BridgeSupportChain;
fromTokenMeta: TokenMeta | {
address: string; // such as xRHEA id on BSC
symbol: string; //such as xRHEA、xPublicAI
decimals: number;
icon: string;
};
toTokenMeta: TokenMeta | {
address: string; // such as xRHEA id on NEAR
symbol: string;
decimals: number;
icon: string;
};
amountIn: string;
sender: string;
};
waitUnstakeXTokenID: string; // such as xRHEA id on NEAR
unstakedTokenID: string; // such as RHEA id on NEAR
nearAccountId: string | ''; // your near accountId
signer: Signer; // await window.ethWeb3Provider?.getSigner();
env?: string; // production
rpcUrl?: string; // ex: https://free.rpc.fastnear.com
}
interface WithdrawParams {
stakeInfo: StakeInfo | {
from: BridgeModel.BridgeSupportChain;
to: BridgeModel.BridgeSupportChain;
fromTokenMeta: TokenMeta | {
address: string; // withdrawTokenIDOnBsc
symbol: string;
decimals: number;
icon: string;
};
toTokenMeta: TokenMeta | {
address: string; // withdrawTokenIDOnNear
symbol: string;
decimals: number;
icon: string;
};
amountIn: string;
sender: string;
};
withdrawTokenIDOnNear: string; // you token id on near
withdrawTokenIDOnBsc: string; // you token id on bsc
receiver: string; // your near wallet address
withdrawBalance: string; // your near account token balance
evmRpcUrl?: string; // source chain rpc such as : "https://bsc.drpc.org" and you can find on chainlist
}