Cookbook
A set of code snippets ready to be used.
#
Get all extensions accountsA dapp will not be aware whether or not the user has the extension installed on their browser until the web3Enable
function is called.
Calling this function returns the amount of extensions installed and for which the user has accepted to share their accounts. Using web3Accounts
, you can then retrieve the visible accounts. See below for web3AccountsSubscribe
usage.
#
Sign a messageHere is an example on how to sign a message with an account that was injected by the extension.
Head to the relevant util-crypto example to see how to verify a signature.
#
Sign and send a transactionThe api is able to retrieve the signer when signAndSend
is called with the address from an account retrieved from the extension.
#
Subscription to extensions' accountsUsing web3AccountsSubscribe
similarly as what we did above with web3Accounts
allows to get all injected accounts, in this case though because we use a subscription, we will be aware of any account change.