Simple Summary
A RPC method to request accounts and to let the user to choose which account he agree to expose to the dapps.
Inspired by EIP-1102.
Adapted to match with Starknet account.
Abstract
Dapps may require a user to connect an account from his wallet.
This RPC method allow dapps to request accounts and let the user choose which account to expose.
Specification
The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”,
and “OPTIONAL” in this document are to be interpreted as described in RFC-2119.
wallet_requestAccounts
This RPC method allows a user to connect one or several accounts from his wallet.
Calling this method SHOULD display to the user the list of available accounts to let him choose which accounts to expose to the dapp.
In case the user reject the connection, the method SHOULD return an error.
Here is the type of this method:
Provider.request('wallet_requestAccounts'): Promise<AccountInterface[]>
Where
AccountInterface
comes from starknetjs
-
The method MUST return a Promise with the selected Account instance.
-
If the user reject the connection, the method MUST reject the Promise.
-
The method MUST always return one account.
-
If the user didn’t select any accounts, he SHOULD NOT be able to validate the connection.
-
In any case, if the user didn’t select any accounts, the method MUST reject the Promise instead.
-
If no accounts are available, the method MUST reject the Promise.
Account usage
The account instance (AccountInterface
) returned by this method can directly be used to execute transactions.
If several accounts are returned, using one or the other account SHOULD end by the wallet to automatically select the good account when displaying confirmation interface.
This way a dapps could manage several accounts and let the user choose which one to use directly from dapps.
Here is an example with 2 accounts selected :
const accounts = await Provider.request('wallet_requestAccounts');
const nbAccounts = accounts.length;
const selectedAccount = accounts[nbAccounts - 1];
selectedAccount.execute(...)