unWallet provider is an EIP1193-compliant provider that provides access to unWallet.
$ npm install unwallet-provider
import { UnWalletProvider } from "unwallet-provider";
const provider = new UnWalletProvider();
EIP1102-compliant account exposure
const accounts = await provider.request<string[]>({
method: "eth_requestAccounts",
});
const txHash = await provider.request<string>({
method: "eth_sendTransaction",
params: [
{
from: "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
to: "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
gas: "0x76c0",
gasPrice: "0x9184e72a000",
value: "0x9184e72a",
data: "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675",
},
],
});
await provider.disable();
import { ethers } from "ethers";
const web3Provider = new ethers.providers.Web3Provider(provider);
Note
RPC methods other than the following are available by setting arbitrary RPC endpoints to the provider. See :ref:`configuration` for details.
none
Array
of DATA (20 Bytes)
- addresses that the user approved to access
// Request
const accounts = await provider.request<string[]>({
method: "eth_requestAccounts",
});
// Result
["0x407d73d8a49eeb85d32cf465507dd71d507100c1"]
none
Array
of DATA (20 Bytes)
- addresses that the user approved to access
// Request
const accounts = await provider.request<string[]>({
method: "eth_accounts",
});
// Result
["0x407d73d8a49eeb85d32cf465507dd71d507100c1"]
none
Number
- integer of the chain ID currently connected
// Request
const chainId = await provider.request<number>({
method: "eth_chainId",
});
// Result
1
DATA
- message to be signedDATA (20 Bytes)
- address of the account that will sign the message
DATA
- signature
// Request
const sig = await provider.request<string>({
method: "personal_sign",
params: [
"0xdeadbeaf",
"0x9b2055d370f73ec7d8a03e965129118dc8f5bf83",
],
});
// Result
"0xa3f20717a250c2b0b729b7e5becbff67fdaef7e0699da4de7ca5895b02a170a12d887fd3b17bfdce3481f10bea41f45ba9f709d39ce8325427b57afcfc994cee1b"
DATA (20 Bytes)
- address of the account that will sign the messageDATA
- message to be signed
DATA
- signature
// Request
const sig = await provider.request<string>({
method: "eth_sign",
params: [
"0x9b2055d370f73ec7d8a03e965129118dc8f5bf83",
"0xdeadbeaf",
],
});
// Result
"0xa3f20717a250c2b0b729b7e5becbff67fdaef7e0699da4de7ca5895b02a170a12d887fd3b17bfdce3481f10bea41f45ba9f709d39ce8325427b57afcfc994cee1b"
DATA (20 Bytes)
- address of the account that will sign the messagesObject
- EIP712-compliant typed structured data to be signed
DATA
- signature
// Request
const sig = await provider.request<string>({
method: "eth_signTypedData",
params: [
"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
{
types: {
EIP712Domain: [
{
name: "name",
type: "string",
},
{
name: "version",
type: "string",
},
{
name: "chainId",
type: "uint256",
},
{
name: "verifyingContract",
type: "address",
},
],
Person: [
{
name: "name",
type: "string",
},
{
name: "wallet",
type: "address",
},
],
Mail: [
{
name: "from",
type: "Person",
},
{
name: "to",
type: "Person",
},
{
name: "contents",
type: "string",
},
],
},
primaryType: "Mail",
domain: {
name: "Ether Mail",
version: "1",
chainId: 1,
verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
},
message: {
from: {
name: "Cow",
wallet: "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
},
to: {
name: "Bob",
wallet: "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB",
},
contents: "Hello, Bob!",
},
},
],
});
// Returns
"0x4355c47d63924e8a72e509b65029052eb6c299d53a04e167c5775fd466751c9d07299936d304c153f6443dfa05f40ff007d72911b6f72307f996231605b915621c"
Note
This method is provided for compatibility with MetaMask.
DATA (20 Bytes)
- address of the account that will sign the messagesString
- JSON encoded EIP712-compliant typed structured data to be signed
DATA
- signature
// Request
const sig = await provider.request<string>({
method: "eth_signTypedData_v4",
params: [
"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
`{"types":{"EIP712Domain":[{"name":"name","type":"string"},{"name":"version","type":"string"},{"name":"chainId","type":"uint256"},{"name":"verifyingContract","type":"address"}],"Person":[{"name":"name","type":"string"},{"name":"wallet","type":"address"}],"Mail":[{"name":"from","type":"Person"},{"name":"to","type":"Person"},{"name":"contents","type":"string"}]},"primaryType":"Mail","domain":{"name":"Ether Mail","version":"1","chainId":1,"verifyingContract":"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"},"message":{"from":{"name":"Cow","wallet":"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"},"to":{"name":"Bob","wallet":"0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"},"contents":"Hello, Bob!"}}`,
],
});
// Returns
"0x4355c47d63924e8a72e509b65029052eb6c299d53a04e167c5775fd466751c9d07299936d304c153f6443dfa05f40ff007d72911b6f72307f996231605b915621c"
Object
- transaction object
from
:DATA (20 Bytes)
- (optional) address that the transaction is send fromto
:DATA (20 Bytes)
- address that the transaction is directed togas
:QUANTITY
- (optional) integer of the gas provided for the transaction executiongasPrice
:QUANTITY
- (optional) integer of the gas price used for each paid gasvalue
:QUANTITY
- (optional) integer of the value sent with the transactiondata
:DATA
- (optional) hash of the invoked method signature and encoded parameters
DATA (32 Bytes)
- transaction hash
const txHash = await provider.request<string>({
method: "eth_sendTransaction",
params: [
{
from: "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
to: "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
gas: "0x76c0",
gasPrice: "0x9184e72a000",
value: "0x9184e72a",
data: "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675",
},
],
});
Note
See also EIP3326.
Object
chainId
: integer ID of the chain as a hexadecimal string
null
await provider.request<null>({
method: "wallet_switchEthereumChain",
params: [
{
chainId: "0x1",
},
],
});
You can execute RPC methods other than :ref:`supported-rpc-methods` by setting arbitrary RPC endpoints to the provider as follows.
const provider = new UnWalletProvider({
rpc: {
// <CHAIN_ID>: "<ENDPOINT>",
1: "https://mainnet.infura.io/v3/YOUR_PROJECT_ID",
137: "https://polygon-mainnet.infura.io/v3/YOUR_PROJECT_ID",
},
});
const count = await provider.request<string>({
method: "eth_getTransactionCount",
params: [
"0x407d73d8a49eeb85d32cf465507dd71d507100c1",
],
});
If allowAccountsCaching
option is true
, the provider caches information about the accounts in local storage so that you do not have to execute eth_requestAccounts each time you instantiate the provider.
const provider = new UnWalletProvider({
allowAccountsCaching: true,
});