Aptos Dapps Integration

(Require app ver > 12.5.0)

Aptos testnet

Aptos devnet

Dapp API

Forum post with discussion There will be some apis that certain wallets may add but there should be a few apis that are standard across wallets. This will make mass adoption easier and will make dapp developers' lives easier.

  • connect({network: 'mainnet' | 'testnet' | 'devnet'}), disconnect(), and isConnected()

  • account()

  • signAndSubmitTransaction(transaction: EntryFunctionPayload)

  • signMessage(payload: SignMessagePayload)

  • Event listening (onAccountChanged(listener), onNetworkChanged(listener))

connect(), disconnect(), isConnected()

It is important that dapps, aren't allow to send requests to the wallet until the user acknowledges that they want to see these requests.

  • connect({network: 'mainnet' | 'testnet' | 'devnet'}) will prompt the user

    • return Promise<PublicAccount>

  • disconnect() allows the user to stop giving access to a dapp and also helps the dapp with state management

    • return Promise<void>

  • isConnected() able to make requests to the wallet to get current state of connection

    • return Promise<boolean>

account()

Needs to be connected The dapp may want to query for the current connected account to get the address or public key.

  • account() no prompt to the user

    • returns Promise<PublicAccount>

signAndSubmitTransaction(transaction: EntryFunctionPayload)

We will be generate a transaction from payload(simple JSON) using the sdk and then sign and submit it to the wallet's node.

  • signAndSubmitTransaction(transaction: EntryFunctionPayload) will prompt the user with the transaction they are signing

    • returns Promise<PendingTransaction>

signMessage(payload: SignMessagePayload)

The most common usecase for this function is to verify identity, but there are a few other possible use cases. You may notice some wallets from other chains just provide an interface to sign arbitrary strings. This can be susceptible to man-in-the-middle attacks, signing string transactions, etc.

Types:

  • signMessage(payload: SignMessagePayload) prompts the user with the payload.message to be signed

    • returns Promise<SignMessageResponse>

An example: signMessage({nonce: 1234034, message: "Welcome to dapp!", address: true, application: true, chainId: true })

This would generate the fullMessage to be signed and returned as the signature:

dApp Integration

dApps can make requests to the wallet from their website:

  • connect(): prompts the user to allow connection from the dApp (neccessary to make other requests)

  • isConnected(): returns if the dApp has established a connection with the wallet

  • account(): gets the address of the account signed into the wallet

  • signAndSubmitTransaction(transaction): signs the given transaction and submits to chain

  • signTransaction(transaction): signs the given transaction and returns it to be submitted by the dApp

  • disconnect(): Removes connection between dApp and wallet. Useful when the user wants to remove the connection.

Verify signature:

Last updated