window.$onekey.ethereum. This API allows websites to request users' Ethereum accounts, read data from blockchains the user is connected to, and suggest that the user sign messages and transactions. The presence of the provider object indicates an Ethereum user.
typeof window !== 'undefined' && window.$onekey.ethereumto detect our provider in browser.
trueif the provider is connected to the current chain, and
requestto submit RPC requests to Ethereum via OneKey Browser Extension. It returns a
Promisethat resolves to the result of the RPC method call.
paramsand return value will vary by RPC method. In practice, if a method has any
params, they are almost always of type
EventEmitterguides elsewhere, but you can listen for events like this:
disconnecthas been emitted, the provider will not accept any new requests until the connection to the chain has been re-restablished, which requires reloading the page. You can also use the
$onekey.isConnected()method to determine if the provider is disconnected.
eth_accountsRPC method changes.
eth_accountsreturns an array that is either empty or contains a single account address. The returned address, if any, is the address of the most recently used account that the caller is permitted to access. Callers are identified by their URL origin, which means that all sites with the same origin share the same permissions.
accountsChangedwill be emitted whenever the user's exposed account address changes.
eth_accountsarray to be able to contain multiple addresses in the near future.
eth_subscribe, each subscription update will be emitted as a
messageevent with a
codeproperty to determine why the request failed.