Access a User’s Dapper Account
To gain user account information, your dapp will need to do a one time request for approval by calling the window.ethereum.enable
function that the provider supplies.
If a user agrees to allow an app access to their wallet info, the call will return an array of accounts similar to eth_accounts
; the enable
function is actually just a permission wrapper around eth_accounts
.
Future calls to window.ethereum.enable
will not re-request permission, it will just return user accounts as expected.
Here’s an example:
async function init() {
if (typeof window.ethereum === 'undefined') {
// Handle case where user hasn't installed Dapper.
return;
}
try {
// If a user is logged in to Dapper and has previously approved the dapp,
// `ethereum.enable` will return the result of `eth_accounts`.
const accounts = await window.ethereum.enable();
} catch (error) {
// Handle error. If the user rejects the request for access, then
// `ethereum.enable` will throw an error.
}
}
After gaining the user’s permission to access account data, you’ll be able to structure and make RPC calls that require their wallet address as normal ( e.g. personal_sign
, eth_sendTransaction
).