ewallet_sdk_eth
- This package is a variant of
@oko-wallet/ewallet-sdk-core for Ethereum.
- It provides a way to interact with Ethereum wallets using
@oko-wallet/ewallet-sdk-core.
Example
Create Wallet
import { initKeplrEwallet } from "@oko-wallet/ewallet-sdk-core";
import { initEthEWallet } from "@oko-wallet/ewallet-sdk-eth";
const eWallet = await initKeplrEwallet({
element_id: "oko-wallet",
});
const ethEWallet = await initEthEWallet({
eWallet,
});
Get Provider
const provider = await ethEWallet.getEthereumProvider();
const chainId = await provider.request({
method: "eth_chainId",
});
Viem Integration
const account = await toViemAccount(eWallet);
import { createPublicClient, createWalletClient, custom } from "viem";
const provider = await ethEWallet.getEthereumProvider();
const publicClient = createPublicClient({
chain: sepolia,
transport: custom(provider),
});
const walletClient = createWalletClient({
account: (
await provider.request({
method: "eth_accounts",
})
)[0],
chain: sepolia,
transport: custom(provider),
});
Ethers Integration
import { BrowserProvider } from "ethers";
const provider = new BrowserProvider(await ethEWallet.getEthereumProvider());
const blockNumber = await provider.getBlockNumber();
const signer = await provider.getSigner();
const signature = await signer.signMessage("Hello, world!");
Create Provider only
import { initEWalletEIP1193Provider } from "@oko-wallet/ewallet-sdk-eth";
const provider = await initEWalletEIP1193Provider({
id: "oko-wallet",
});
or create a provider manually
import { initEWalletEIP1193Provider } from "@oko-wallet/ewallet-sdk-eth";
const provider = new EWalletEIP1193Provider({
id: `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
chains: [
{
chainId: "0x1",
chainName: "Ethereum Mainnet",
nativeCurrency: {
name: "Ether",
symbol: "ETH",
decimals: 18,
},
rpcUrls: ["https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID"],
blockExplorerUrls: ["https://etherscan.io"],
},
],
});
Tests
$ yarn test
$ yarn test:debug
$ yarn test:watch
$ yarn test:coverage