Ethereum Provider API
Sender injects a global JavaScript API into websites visited by its users using the window.sender.ethereum
provider object. 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.
Properties
window.sender.ethereum.isSender
This property is true
if the user has Sender installed.
Methods
eth_requestAccounts
Requests that the user provide an Ethereum address to be identified by. Use this method to access a user's accounts. This method is specified by EIP-1102.
Example:
wallet_getPermissions
Gets the caller's current permissions. This method returns an array of the caller's permission objects. If the caller has no permissions, the array is empty.
wallet_requestPermissions
Requests permissions from the user. The request causes a Sender popup to appear. You should only request permissions in response to a direct user action, such as a button click.
Example:
window.sender.ethereum.request(args)
Use this method to submit RPC API requests to Ethereum using Sender It returns a promise that resolves to the result of the RPC method call.
The following is an example of using window.sender.ethereum.request(args)
to call eth_sendTransaction
:
Events
The Sender provider emits events using the Node.js EventEmitter
API. The following is an example of listening to the accountsChanged
event. You should remove listeners once you're done listening to an event (for example, on component unmount in React).
The first argument of window.sender.ethereum.removeListener
is the event name, and the second argument is a reference to the function passed to window.sender.ethereum.on
for the event.
accountsChanged
The Sender provider emits this event when the return value of the eth_accounts
RPC method changes. eth_accounts
returns either an empty array, or an array that contains the address of the most recently used account 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.
This means that the provider emits accountsChanged
when the user's exposed account address changes. Listen to this event to handle accounts.
chainChanged
The provider emits this event when the currently connected chain changes. Listen to this event to detect a user's network.
connect
The provider emits this event when it's first able to submit RPC requests to a chain.
disconnect
The provider emits this event if it becomes unable to submit RPC requests to a chain. In general, this only happens due to network connectivity issues or some unforeseen error.
message
The provider emits this event when it receives a message that the user should be notified of. The type
property identifies the kind of message.
Last updated