Establishing a Connection

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();

The connect() call will return a Promise 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

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();

Last updated