EvmAccountMappingProvider
EvmAccountMappingProvider
is a provider implementation that uses the EVM account mapping pallet. It use viem to interact with EVM wallet, so you can use almost all EVM wallets (since all of them can be integrated with viem).
Usage
Follow up is two snippets to show how it works with browser wallet extension and init from a private key.
import { getClient } from '@phala/sdk'
export const client = await getClient({ transport: 'wss://api.phala.network/ws' })
// ---cut---
import { EvmAccountMappingProvider } from '@phala/sdk'
import { createWalletClient, custom, WalletClient, Chain, Transport, Account } from 'viem'
import { mainnet } from 'viem/chains'
async function setWallet<
transport extends Transport = Transport,
chain extends Chain | undefined = Chain | undefined,
account extends Account | undefined = Account | undefined
>(walletClient: WalletClient<transport, chain, account>) {
}
const walletClient = createWalletClient({ chain: mainnet, transport: custom((window as any).ethereum) })
const [address] = await walletClient.requestAddresses()
const provider = await EvmAccountMappingProvider.create(client.api, walletClient, { address })
create
Get a provider instance and connected to the EVM wallet.
Parameters
api
ApiPromise
walletClient
WalletClient
The WalletClient
instance from viem. You can learn more about that from the viem documentation.
account
Account
A JSON-RPC Account or Local Account (Private Key, etc) from viem.
Or you can use a plain literval object with address
property.
options
(optional)
EvmAccountMappingProviderOptions
msg
:string
. The message request to access the public key of selected wallet.SS58Prefix
:number
. The SS58 prefix for the mapped substrate address.
evmAccount
Account
The Account
object for the EVM wallet.
compressedPubkey
Address
The compressed public key for the EVM wallet.