Install dependencies
-
@solana-mobile/mobile-wallet-adapter-protocol- Base library that implements the MWA client. Include this, but only import
transactfrom the wrapper library.
- Base library that implements the MWA client. Include this, but only import
-
@solana-mobile/mobile-wallet-adapter-protocol-web3js- A convenience wrapper for the base library that enables with
web3.jsprimitives likeTransaction.
- A convenience wrapper for the base library that enables with
Import into a file
Mobile Wallet API Methods
Reference for the Mobile Wallet API for dApps to connect to wallets and receive signing services.transact
This is the first step in using the Mobile Wallet API. Starts a Mobile Wallet Adapter session with a locally installed MWA-compatible wallet.Parameters
callback: (wallet: Web3MobileWallet) => TReturn required
A callback triggered after session establishment, in which the dApp can issue MWA requests to the wallet app, using the wallet object.
config: WalletAssociationConfig optional
Configuration object containing the following fields:
baseUri string optional
URI used for custom wallet association.
Details
Details
As per spec, during session establishment, the wallet may return a custom URI scheme to use for future session establishments. The dApp can choose to use this custom URI by suppyling it through this parameter.
Result
The result will be aPromise<TReturn> with TReturn equal to what is returned from the callback parameter.
Code sample
Return:
Web3MobileWallet.authorize
Non-privileged method. Requests authorization from the connected wallet for access to privileged methods within the session.Parameters
chain: string optional
The chain identifier for the chain with which the dapp intends to interact;
Supported values include “solana:mainnet”, “solana:testnet”, “solana:devnet”, “mainnet-beta”, “testnet”, “devnet”. If not set, defaults to “solana:mainnet”.
identity: object optional
A JSON object containing the following fields:
uri string optional
A URI representing the web address associated with the dapp making this authorization request. If present, it must be an absolute, hierarchical URI.
icon string optional
A relative path (from uri) to an image asset file of an icon identifying the dapp making this authorization request.
name string optional
the display name for this dapp.
features: string[] optional
A list of feature identifiers that the dapp intends to use in the session. Defaults to null.
addresses: string[] optional
A list of base64 encoded account addresses that the dapp wishes to be included in the authorized scope. Defaults to null.
auth_token: string optional
A string representing a unique identifying token previously issued by the wallet to the dapp from a previous call to authorize or clone_authorization. If present, the wallet should attempt to reauthorize the dapp silently without prompting the user.
sign_in_payload: SignInPayload optional
An object containing the Sign-In input fields as described by the Sign In With Solana specification. If present, the wallet should present the SIWS message to the user and include the sign_in_result in the response.
Result:
The result will be a JSON object containing the following fields:auth_token: string: A string representing a unique identifying token issued by the wallet to the dapp. Use this on future connections to reauthorize access to privileged methods.accounts: one or more value objects that represent the accounts to which this auth token corresponds. These objects hold the following properties:address: string:a base64-encoded public key for this account.chains: a list of chain identifiers supported by this account. These should be a subset of the chains supported by the wallet.label: string (optional): a human-readable string that describes the account.display_address: string (optional): the address for this account. The format of this string will depend on the chain, and is specified by the display_address_format fielddisplay_address_format: string (optional): the format of the display_address.features: string[] (optional): a list of feature identifiers that represent the features that are supported by this account. These features must be a subset of the features returned by get_capabilities. If this parameter is not present the account has access to all available features (both mandatory and optional) supported by the wallet.icon: string (optional): a data URI containing a base64-encoded SVG, WebP, PNG, or GIF image of an icon for the account. This may be displayed by the app.
wallet_uri_base: string (optional): A custom URI specified by the wallet that the dapp should use for subsequent connections.sign_in_result: object (optional): If the authorize request included the SIWSsign_in_payload, the result will be returned here as an object containing the following:address: string: the address of the account that was signed in. The address of the account may be different from the provided input address, but must be the address of one of the accounts returned in the accounts field.signed_message: string: the base64-encoded signed message payloadsignature: string: the base64-encoded signaturesignature_type: string (optional): the type of the message signature produced. If not provided in this response, the signature must be “ed25519”.
Code sample:
Result:
Web3MobileWallet.deauthorize
Non-privileged method. This method will make the providedauth_token invalid for use (if it ever was valid).
If, during the current session, the specified auth token was returned by the most recent call to authorize or reauthorize, the session will be placed into the unauthorized state.
Parameters
auth_token: string required
An auth token string previously returned by a call to authorize, reauthorize, or clone_authorization, which will be deauthorized.
Result:
The result will be an empty JSON object.Code sample:
Result:
Web3MobileWallet.getCapabilities
Non-privileged method. This method enumerates the capabilities and limits of the wallet’s MWA implementation.Parameters
NoneResult:
The result will be a JSON object as defined inauthorize, but the values may be updated and differ from the values originally provided in the authorize response for the auth token.
max_transactions_per_request: (optional) if present, the max number of transaction payloads which can be signed by a singlesign_transactionsorsign_and_send_transactionsrequest. If absent, the implementation doesn’t publish a specific limit for this parameter.max_messages_per_request: (optional) if present, the max number of transaction payloads which can be signed by a single sign_messages request. If absent, the implementation doesn’t publish a specific limit for this parameter.supported_transaction_versions: the Solana network transaction formats supported by this wallet endpoint. Allowed values are those defined forTransactionVersion(for e.g., “legacy”, 0, etc).features: a list of feature identifiers for the optional features supported by the wallet. Dapps can assume that mandatory features are supported by the wallet.
Code sample:
Result:
Web3MobileWallet.signAndSendTransactions
Privileged method. This method requests the wallet to sign the specified transactions with the private keys for the authorized addresses, submit the transactions to the network, and return the transaction signatures to the dapp.Parameters
transactions: Transaction[] required
An array of one or more transactions to sign and send. The transaction are of type Transaction or VersionedTransaction from the web3.js library.
minContextSlot: number
The minimum slot number at which to perform preflight transaction checks.
Result:
string[]- the corresponding base64-encoded transaction signatures.
Code sample:
Result:
Web3MobileWallet.signTransactions
Privileged method. Request to sign the given transactions with the private keys for the requested authorized account.Parameters
transactions: Transaction[] required
An array of one or more transactions to sign. The transaction are of type Transaction or VersionedTransaction from the web3.js library.
Result:
Transaction[]- the corresponding Transactions signed with the private keys for the requested authorized account addresses.
Code sample:
Result:
Web3MobileWallet.signMessages
Privileged method. Request to sign the given messages payloads with the private keys for the requested authorized account.Parameters
addresses: string[] required
One or more base64-encoded addresses of the accounts which should be used to sign message. These should be a subset of the addresses returned by authorize or reauthorize for the current session’s authorization.
payloads: Uint8Array[] required
One or more byte arrays where each byte array is a message payload to sign.
Result:
Uint8Array[]- the corresponding base64-encoded signed message payloads.
