Cookbook
A set of code snippets ready to be used.
Get all extensions accounts#
A 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 message#
Here 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 transaction#
The api is able to retrieve the signer when signAndSend is called with the address from an account retrieved from the extension.
Subscription to extensions' accounts#
Using 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.