Aptos dApp Integration

Install CLV Wallet

To use CLV Wallet for your Aptos dApp, your users need to install CLV Wallet Chrome extension in their browser. CLV Wallet injects an clover_aptos object into the window of any dApp that the user visits.

To check whether the user has installed CLV Wallet, please use the following check:

const isCLVInstalled = window.clover_aptos

If CLV Wallet is not installed, you can navigate user to install CLV Wallet first. For example

const getCLVWallet = () => {
    if ('clover_aptos' in window) {
        return window.clover_aptos;
    } else {
        window.open('https://clv.org/?type=wallet', `_blank`);
    }
}

Connect to CLV Wallet

After clover_aptos object is injected into the dApp, we can connect to CLV Wallet by calling wallet.connect(). When this function is called, it will prompt user a dialog to approve or reject the interactions between your web app and CLV Wallet. Once connection is approved, you can easily get user's current wallet address. Sample code:

const wallet = getCLVWallet();
try {
    const response = await wallet.connect();
    console.log(response); // { address: string, publicKey: string }

    const account = await wallet.account();
    console.log(account); // { address: string, publicKey: string }
} catch (error) {
    // { code: 500, message: "The request was cancelled."}
}

Disconnect CLV Wallet

If you want the dApp to disconnect from CLV Wallet, you should just call wallet.disconnect().

Transaction Signing

Once your dApp is connected with CLV Wallet, it can prompt to user to sign and send transactions to the Aptos blockchain.

Case 1: Sign and Submit

Case 2: Sign only

Message Signing

A dApp can call wallet.signMessage(payload: SignMessagePayload) to sign a message using CLV Wallet.

The above function call will return Promise<SignMessageResponse>. Types info are:

Example message and response

The above would generate a full message to be signed and returned as the signature:

Signature Verifying

Last updated