Martian Wallet Dev Docs
HomeChrome web store
  • Introduction
  • 🏗️Integration
    • Detecting the Provider
    • Establishing a Connection
    • Displaying Your App
  • ⚙️methods
    • Aptos
      • Generate Transaction
      • Sign Transaction
      • Submit Transaction
      • Sign and Submit Transaction
      • Sign Generic Transaction
      • Generate Sign and Submit Transaction
      • Create Collection
      • Create Token
      • Add Network
      • Change Network
      • Get Networks
      • Get Transaction
      • Get Transactions
      • Get Account Transactions
      • Get Account Resources
      • Get Account
      • Get Chain Id
      • Get Ledger Info
    • Sui
      • Sign Transaction Block
      • Sign and Execute Transaction
      • Get Public Key
      • Get Old Address
      • Get Accounts
    • Sign Message
    • Get Network
    • Get Current Blockchain
    • Cancel Submitted Transactions
    • Network Change Event
    • Account Change Event
Powered by GitBook
On this page
  • Connecting
  • Disconnecting
  1. Integration

Establishing a Connection

PreviousDetecting the ProviderNextDisplaying Your App

Last updated 2 years ago

In order to start interacting with Martian Wallet for Sui & Aptos, an app must first establish a connection. This connection request will prompt the user for permission to share their address, indicating that they are willing to interact further. Once permission is established for the first time, the web application's domain will be whitelisted for future connection requests.

Similarly, it is possible to terminate the connection both on the application and the user side.

Connecting

The recommended and easiest way to connect to Martian wallet is by invoking window.martian.connect().

await window.martian.connect();
// Permissions: ['viewAccount', 'suggestTransactions']
await window.martian.sui.connect(['viewAccount', 'suggestTransactions']);

The connect() call will return a that resolves when the user accepts the connection request. An example of the response is given below:

{
    address: "0x2d5b190a5261c3715c452b89d61549718503171356109805755e4590d1b74399"
    method: "connected"
    publicKey: "0x3d473ebb20ed4264a10083978af3f6cde9ed0d84ee285885c8e5f18f22773926"
    status: 200
}

Once the web application is connected to Martian wallet, it will be able to read the connected account's address and publicKey by await window.martian.account()and will be able to prompt the user for additional transactions. It also exposes a convenience isConnected.

await window.martian.account()
// {  
//    address: '0x2d5b190a5261c3715c452b89d61549718503171356109805755e4590d1b74399', 
//    publicKey: '0x3d473ebb20ed4264a10083978af3f6cde9ed0d84ee285885c8e5f18f22773926'
// }
await window.martian.isConnected()
// true
await window.martian.sui.isConnected()
// true

After a web application connects to Martian wallet for the first time, it becomes whitelisted. Once whitelisted, it's possible for the application to automatically connect to Martian wallet on subsequent visits or page refreshes.

Disconnecting

Disconnecting mirrors the same process as connecting. However, it is also possible for the wallet to initiate the disconnection, rather than the application itself. For this reason, it's important for applications to gracefully handle a disconnect event.

await window.martian.disconnect();
await window.martian.sui.disconnect();
🏗️
Promise