@ryze-blockchain/ethereum v2.0.8
Ethereum
An opinionated wrapper to simplify the integration with ethers, a popular Ethereum library.
Installation
npm i @ryze-blockchain/ethereum
Usage
- Initialize
// ethereum.ts
import { Ethereum, ChainId, WalletInfo } from '@ryze-blockchain/ethereum'
export const ethereum = new Ethereum({
defaultChainId: ChainId.AVAX_TESTNET,
availableChainIds: [ChainId.AVAX_TESTNET],
chainToRpcMap: {
[ChainId.AVAX_TESTNET]: ['https://api.avax-test.network/ext/bc/C/rpc'],
},
onWalletUpdate: (walletInfo: WalletInfo | null) => {
// set walletInfo in your state management plugin
},
})
- Connect to a wallet provider
// your wallet component
import { isEthersError, isProviderError, ProviderErrorCode, WalletApplication } from '@ryze-blockchain/ethereum'
import { ethereum } from './ethereum.ts'
// You can use any one of the available WalletApplications
const connectWallet = async (walletApplication: WalletApplication) => {
return await ethereum.walletManager.connect(walletApplication, {
onReject: () => { throw new Error('User rejected wallet connection') },
onRequestAlreadyPending: () => { throw new Error('Wallet connection already pending') },
onProviderUnavailable: () => { throw new Error('Wallet provider not available') },
})
}
- Request to set a chain in the user's wallet
// your chain component
import { isEthersError, isProviderError, ProviderErrorCode, ChainId } from '@ryze-blockchain/ethereum'
import { ethereum } from './ethereum.ts'
const setChain = async (chainId: ChainId) => {
return await ethereum.walletManager.setChain(chainId, {
onReject: () => { throw new Error('Request rejected by the user') },
onRequestAlreadyPending: () => { throw new Error('Request to switch chain already pending') },
})
}
5 days ago
6 days ago
21 days ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
4 months ago
4 months ago
7 months ago
7 months ago
10 months ago
10 months ago
10 months ago
9 months ago
10 months ago
9 months ago
10 months ago
10 months ago
10 months ago
7 months ago
8 months ago
8 months ago
8 months ago
9 months ago
9 months ago
9 months ago
10 months ago
10 months ago
10 months ago
10 months ago
11 months ago
11 months ago
11 months ago
12 months ago
12 months ago
12 months ago
11 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
12 months ago
12 months ago
12 months ago
11 months ago
11 months ago
12 months ago
11 months ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago