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
  • Substrate Blockchains Integration
  • EVM Blockchains Integration
  • Solana Blockchain Integration
  1. CLV Wallet Developer Guide

Web Wallet dApp Integration

dApps can easily integrate CLV Web Wallet for transaction & message signing. The SDK @clover-network/web-wallet-sdk is needed for the integration.

The SDK can be installed as follows:

yarn add @clover-network/web-wallet-sdk

Substrate Blockchains Integration

CLV web wallet supports dApps on substrate-based blockchains, such as Polkadot, Kusama, Acala, etc. The sample code is as follows:

import CloverWebInjected from '@clover-network/web-wallet-sdk';
import { web3Enable, web3Accounts, web3FromAddress } from "@polkadot/extension-dapp";

const clvInject = new CloverWebInjected({ zIndex: 99999 });

const initInjector = async () => {
    await clvInject.init({
      network: {
        chainId: '0x1',
      },
      enableLogging: true,
    });
    
    await clvInject.polkadotLogin(); // After this success, the injector has been injected into web page
    const injected: any = await web3Enable('clv'); // injector could be get in standard way
}

// sign message
const polkadotSignMessage = async () => {
    const polkadotAddress = await web3Accounts({ ss58Format: 42 });
    const wrapped = u8aWrapBytes(polkadotAddress.toLowerCase());
    const ret = await currentInjected.signer.signRaw({
      data: u8aToHex(wrapped),
      address: polkadotAddress,
      type: "bytes",
    });
  }
  
// send transaction
polkadotSignTransaction = async () => {
  const wsProvider = new WsProvider('wss://rpc.polkadot.io');
  const api = await ApiPromise.create({provider: wsProvider});
  const polkadotAddress = await web3Accounts({ ss58Format: 42 });
  const currentClvAccount = polkadotAddress
  const injected = await web3FromAddress(currentClvAccount)
  api.setSigner(injected.signer)
  const unsub = await api.tx.balances
    .transfer(currentClvAccount, 0)
    .signAndSend(currentClvAccount, (result) => {

      if (result.status.isInBlock) {
        // in block
      } else if (result.status.isFinalized) {
        unsub();
      }
    })
  }

EVM Blockchains Integration

CLV web wallet supports dApps on EVM blockchains, such as Ethereum, CLV Parachain (P-Chain), Moonbeam and etc. The sample code is as follows:

import CloverWebInjected from '@clover-network/web-wallet-sdk';

const clvInject = new CloverWebInjected({ zIndex: 99999 });

const initInjector = async () => {
    await clvInject.init({
      network: {
        chainId: '0x1',
      },
      enableLogging: true,
    });
    
    await clvInject.login();
    clvInject.provider.on('accountsChanged', (accounts) => {
      // do something
    });
}tye

// send transaction
const send = (): void => {
  const web3 = new Web3(clvInject.provider)
  const accounts = await web3.eth.getAccounts();
  const publicAddress = accounts[0]
  web3.eth.sendTransaction({ 
      from: publicAddress, 
      to: publicAddress, 
      value: web3.utils.toWei('0.01') 
    })
}

// eth_sign
const signMessage = (): void => {
  const web3 = new Web3(clvInject.provider)
  const accounts = await web3.eth.getAccounts();
  const publicAddress = accounts[0]
  // hex message
  const message = '0x000000000000000000000000000000000000';
  web3.currentProvider.send(
    {
      method: 'eth_sign',
      params: [publicAddress, message],
      jsonrpc: '2.0',
    },
    (err: Error, result: any) => {
      // error handle
    },
  );
}

// personal message
const signPersonalMsg = async () => {
    try {
      const web3 = new Web3(clvInject.provider)
      const accounts = await web3.eth.getAccounts();
      const publicAddress = accounts[0]
      const message = 'Example';
      const hash = web3.utils.sha3(message);
      const sig = await web3.eth.personal.sign(hash, publicAddress, '');
    } catch (error) {
      //error
    }
  }

// eth_signTypedData, eth_signTypedData_v3, eth_signTypedData_v4 are also supported

Solana Blockchain Integration

CLV web wallet supports dApps on Solana. The sample code is as follows:

import CloverWebInjected from '@clover-network/web-wallet-sdk';

const clvInject = new CloverWebInjected({ zIndex: 99999 });

const initInjector = async () => {
  await clvInject.init({
    network: {
      chainId: '0x1',
    },
    enableLogging: true,
  });
  
  await clvInject.solLogin();
}

const sendSolana = async () => {
  const solAddress = await clvInject.clover_solana.getAccount();
  const connection = new solanaWeb3.Connection(
    solanaWeb3.clusterApiUrl('mainnet-beta'),
    'confirmed',
  );
  const fromPubkey = new solanaWeb3.PublicKey(solAddress);
  const toPubkey = new solanaWeb3.PublicKey(solAddress);
  const transaction = new solanaWeb3.Transaction().add(
    solanaWeb3.SystemProgram.transfer({
      fromPubkey: fromPubkey,
      toPubkey: toPubkey,
      lamports: solanaWeb3.LAMPORTS_PER_SOL * 0,
    }),
  );

  const block = await connection.getRecentBlockhash('max');
  transaction.recentBlockhash = block.blockhash;
  transaction.setSigners(fromPubkey);

  const sss = await clvInject.clover_solana.signTransaction(transaction);
  const rawTransaction = sss.serialize();
  const a = await connection.sendRawTransaction(rawTransaction, {
    skipPreflight: false,
    preflightCommitment: 'single',
  });

  this.console('transaction hash:' + a);
}

const sendSolanaAll = async () => {
  const solAddress = await clvInject.clover_solana.getAccount();
  const connection = new solanaWeb3.Connection(
    solanaWeb3.clusterApiUrl('mainnet-beta'),
    'confirmed',
  );
  const fromPubkey = new solanaWeb3.PublicKey(solAddress);
  const toPubkey = new solanaWeb3.PublicKey(solAddress);
  const transaction = new solanaWeb3.Transaction().add(
    solanaWeb3.SystemProgram.transfer({
      fromPubkey: fromPubkey,
      toPubkey: toPubkey,
      lamports: solanaWeb3.LAMPORTS_PER_SOL * 0,
    }),
  );

  const block = await connection.getRecentBlockhash('max');
  transaction.recentBlockhash = block.blockhash;
  transaction.setSigners(fromPubkey);

  const sss = await clvInject.clover_solana.signAllTransactions([transaction]);
  const rawTransaction = sss[0].serialize();
  const a = await connection.sendRawTransaction(rawTransaction, {
    skipPreflight: false,
    preflightCommitment: 'single',
  });

  this.console('transaction hash:' + a);
}
PreviousAptos dApp IntegrationNextdApp Interaction Protocol

Last updated 2 years ago