CLV Documentations
CLV DOC
CLV DOC
  • Intro to CLV
    • About CLV πŸ€
    • Clover Finance Rebrands to CLV
    • What is CLV Chain?
    • What is CLV Wallet?
    • What is $CLV Token?
    • πŸ“£ CLV Official Channels
    • 🏘 CLV Community Channels
  • Use CLV Chain
    • πŸ“š Beginner’s Guide
      • Setup CLV Wallet
      • Setup Metamask Wallet
      • How to Get $CLV
      • Bridge Other Assets to CLV P-Chain (Parachain)
    • 🌐 Network Details
    • 🏦 Economics
      • Tokenomics
      • Inflation Design
    • πŸ—³οΈGovernance
    • πŸ™‹πŸ» CLV Chain FAQ
    • CLV P-Chain EVM Explorer
    • $CLV Cross-Chain Explorer
    • $CLV Cross-Chain Transfer
  • CLV Validator & Staking
    • What are Nominator & Validator?
    • Stake as a Nominator
    • Running a Validator or RPC Node
    • Staking FAQ
  • Use CLV Wallet
    • πŸ’° Download CLV Wallet
      • Browser Extension (Google Chrome & Brave)
      • Apple iOS (Mobile)
      • Android (Mobile)
      • Web Wallet (Universal)
    • πŸ“± CLV Mobile Wallet
    • πŸ–₯ CLV Extension Wallet
    • πŸ•ΈοΈ CLV Web Wallet
  • CLV Chain Developer Guide
    • Getting Started
    • Using Local Node
      • Using MetaMask
      • Using Remix
      • Using Web3.js
    • Using Testnet
      • Create an account
      • Faucet
      • Run a Testnet Node
      • Connect to Testnet
    • dApp Example
      • Setup dApp project
      • Setup truffle
      • The Counter Contract
      • Deploy Contract
      • Counter Webapp
    • Test Cases
    • Technical Documentations
      • CLV EVM
      • Developers Incentive
      • CLV Accounts Binding
      • Virtual Ethereum Address Binding
      • Query Balance
      • Transaction Finality
      • Web3 Compatibility
        • eth_protocolVersion
        • eth_syncing
        • eth_hashrate
        • eth_coinbase
        • eth_mining
        • eth_chainId
        • eth_gasPrice
        • eth_accounts
        • eth_blockNumber
        • eth_getBalance
        • eth_getStorageAt
        • eth_getBlock
        • eth_getTransactionCount
        • eth_getBlockTransactionCount
        • eth_getBlockUncleCount
        • eth_getCode
        • eth_sendTransaction
        • eth_sendSignedTransaction
        • eth_call
        • eth_estimateGas
        • eth_getTransaction
        • eth_getTransactionByBlockHashAndIndex
        • eth_getTransactionByBlockNumberAndIndex
        • eth_getTransactionReceipt
        • eth_getUncle
        • eth_getLogs
        • eth_getWork
        • eth_submitWork
        • eth_submitHashrate
        • eth_subscribe
        • eth_unsubscribe
        • net_version
        • net_peerCount
        • net_listening
        • web3_clientVersion
        • web3_sha3
      • CLV P-Chain Integration
  • CLV Wallet Developer Guide
    • EVM dApp Integration
    • Substrate dApp Integration
    • Solana dApp Integration
    • Kadena dApp Integration
    • Aptos dApp Integration
    • Web Wallet dApp Integration
    • dApp Interaction Protocol
    • Wallet Integration QA
  • CLV Ecosystem
    • 🏞️ Ecosystem Partners
      • CLV Chain
      • CLV Wallet
    • 🌱 Incentive Programs
      • CLV Ecosystem Grant
      • CLV Wallet Integration Grant
      • CLV Bug Bounty Program
    • Whitelist Assets on Clover P-Chain
    • Bridge assets into CLV P-Chain
  • Assets
    • πŸ”€ Glossary
      • Blockchain (in General)
      • Polkadot
      • Wallet
    • 🎟️ CLV - Polkadot Parachain Auction 2021
      • Parachain Auction Rule Announcement
      • Parachain Winning Reward Announcement
    • πŸ›οΈ Brand Pack
    • πŸ“„ Whitepaper
Powered by GitBook
On this page
  • Install CLV Wallet
  • Connect to CLV Wallet
  • Disconnect CLV Wallet
  • Transaction Signing
  • Case 1: Sign and Submit
  • Case 2: Sign only
  • Message Signing
  • Example message and response
  • Signature Verifying
  1. CLV Wallet Developer Guide

Aptos dApp Integration

PreviousKadena dApp IntegrationNextWeb Wallet dApp Integration

Last updated 2 years ago

Install CLV Wallet

To use CLV Wallet for your Aptos dApp, your users need to install in their browser. CLV Wallet injects an clover_aptos object into the 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().

await 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

const wallet = getCLVWallet();

const transaction = {
    arguments: [address, '1'],
    function: '0x1::coin::transfer',
    type: 'entry_function_payload',
    type_arguments: ['0x1::aptos_coin::MyCoin'],
};

try {
    const tx = await wallet.signAndSubmitTransaction(transaction);
    console.log(tx.hash); // this is the transaction hash
    
    return tx;
} catch (error) {
    // see "Errors"
}

Case 2: Sign only

const wallet = getAptosWallet(); // see "Connecting"

// Example Transaction
const transaction = {
    arguments: [address, '1'],
    function: '0x1::coin::transfer',
    type: 'entry_function_payload',
    type_arguments: ['0x1::aptos_coin::MyCoin'],
};

try {
    const signTransaction = await wallet.signTransaction(transaction);
    console.log(signTransaction); // Uint8Arry for signed transaction
} catch (error) {
    // see "Errors"
}

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:

export interface SignMessagePayload {
  address?: boolean; // Should we include the address of the account in the message
  application?: boolean; // Should we include the domain of the dapp
  chainId?: boolean; // Should we include the current chain id the wallet is connected to
  message: string; // The message to be signed and displayed to the user
  nonce: string; // A nonce the dapp should generate
}

export interface SignMessageResponse {
  address: string;
  application: string;
  chainId: number;
  fullMessage: string; // The message that was generated to sign
  message: string; // The message passed in by the user
  nonce: string,
  prefix: string, // Should always be APTOS
  signature: string; // The signed full message
}

Example message and response

signMessage({nonce: 1234, message: "Welcome to CLV Wallet!" });

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

APTOS
nonce: 1234
message: Welcome to CLV Wallet!

Signature Verifying

import nacl from 'tweetnacl';

const message = "hello";
const nonce = "random_string"

try {
  const response = await window.clover_aptos.signMessage({
    message,
    nonce,
  });
  const { publicKey } = await window.clover_aptos.account();
  // Remove the 0x prefix
  const key = publicKey!.slice(2, 66);
  const verified = nacl.sign.detached.verify(
    Buffer.from(response.fullMessage), 
    Buffer.from(response.signature, 'hex'), 
    Buffer.from(key, 'hex')
  );
  console.log(verified);
} catch (error) {
  console.error(error);
}
CLV Wallet Chrome extension
window