CLV Accounts Binding

Why need Account Binding

As explained in this section, CLV Parachain is a dual blockchain which support both EVM transactions as well as Polkadot like transactions.
Account binding only happens on CLV Parachain, you can bind your CLV address to a CLV EVM address. Once you bind the accounts, you can use one account to interact with both EVM-based dApps as well as Substrate-based dApps.
Here are the features of CLV accounts binding (suppose you have done the accounts binding, for example bind your CLV address: 5DyCG7icXFuq8WtLd7iLi3umczKf84SAvp7w7Rw44RFEU8Yf with EVM address: 0xe6206C7f064c7d77C6d8e3eD8601c9AA435419cE)
  1. 1.
    The above addresses will have the same balance. Other people can send CLV to any of the above account, and you can receive the CLV. At the same time, you can send CLV to other people using any of the above account.
  2. 2.
    If you only have CLV in 0xe6206C7f064c7d77C6d8e3eD8601c9AA435419cE, you can't deploy or interact with CLV smart contract. Once you bind the account with a EVM address, you are able to deploy and interact with CLV smart contract.

How to Bind the Account

  1. 1.
    Using CLV Wallet, the version should be above 1.0.3
  2. 2.
    Using the following sample code๏ผš
1
const API = require("@polkadot/api")
2
const Web3 = require("web3")
3
const web3 = new Web3("https://rpc-2.clover.finance")
4
const cloverTypes = require('@clover-network/node-types')
5
โ€‹
6
const PUB_KEY = "0xe6206C7f064c7d77C6d8e3eD8601c9AA435419cE"
7
const PRIV_KEY = "0xa504b64992e478a6846670237a68ad89b6e42e90de0490273e28e74f084c03c8"
8
const CLOVER_SEEDS = "your 12 seed words"
9
โ€‹
10
async function run() {
11
const wsProvider = new API.WsProvider('wss://api-2.clover.finance');
12
const api = await API.ApiPromise.create({
13
provider: wsProvider,
14
types: cloverTypes
15
});
16
const keyring = new API.Keyring({ type: 'sr25519' });
17
const alice = keyring.addFromUri(CLOVER_SEEDS);
18
let nonce = await api.rpc.system.accountNextIndex(alice.address);
19
web3.eth.accounts.wallet.add(PRIV_KEY);
20
let signature = await web3.eth.sign(`clover evm:${web3.utils.bytesToHex(alice.publicKey).slice(2)}`, PUB_KEY);
21
โ€‹
22
await api.tx.evmAccounts
23
.claimAccount(PUB_KEY, web3.utils.hexToBytes(signature))
24
.signAndSend(alice, {
25
nonce,
26
}, ({ events = [], status }) => {
27
if (status.isFinalized) {
28
console.log(`${alice.address} has bound with EVM address: ${PUB_KEY}`)
29
}
30
});
31
}
32
โ€‹
33
run()
Copied!
โ€‹
โ€‹