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:
1
yarn add @clover-network/web-wallet-sdk
Copied!

Substrate Blockchains Integration

CLV web wallet supports dApps on substrate-based blockchains, such as Polkadot, Kusama, Acala, etc. The sample code is as follows:
1
import CloverWebInjected from '@clover-network/web-wallet-sdk';
2
import { web3Enable, web3Accounts, web3FromAddress } from "@polkadot/extension-dapp";
3
​
4
const clvInject = new CloverWebInjected({ zIndex: 99999 });
5
​
6
const initInjector = async () => {
7
await clvInject.init({
8
network: {
9
chainId: '0x1',
10
},
11
enableLogging: true,
12
});
13
14
await clvInject.polkadotLogin(); // After this success, the injector has been injected into web page
15
const injected: any = await web3Enable('clv'); // injector could be get in standard way
16
}
17
​
18
// sign message
19
const polkadotSignMessage = async () => {
20
const polkadotAddress = await web3Accounts({ ss58Format: 42 });
21
const wrapped = u8aWrapBytes(polkadotAddress.toLowerCase());
22
const ret = await currentInjected.signer.signRaw({
23
data: u8aToHex(wrapped),
24
address: polkadotAddress,
25
type: "bytes",
26
});
27
}
28
29
// send transaction
30
polkadotSignTransaction = async () => {
31
const wsProvider = new WsProvider('wss://rpc.polkadot.io');
32
const api = await ApiPromise.create({provider: wsProvider});
33
const polkadotAddress = await web3Accounts({ ss58Format: 42 });
34
const currentClvAccount = polkadotAddress
35
const injected = await web3FromAddress(currentClvAccount)
36
api.setSigner(injected.signer)
37
const unsub = await api.tx.balances
38
.transfer(currentClvAccount, 0)
39
.signAndSend(currentClvAccount, (result) => {
40
​
41
if (result.status.isInBlock) {
42
// in block
43
} else if (result.status.isFinalized) {
44
unsub();
45
}
46
})
47
}
48
​
Copied!

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:
1
import CloverWebInjected from '@clover-network/web-wallet-sdk';
2
​
3
const clvInject = new CloverWebInjected({ zIndex: 99999 });
4
​
5
const initInjector = async () => {
6
await clvInject.init({
7
network: {
8
chainId: '0x1',
9
},
10
enableLogging: true,
11
});
12
13
await clvInject.login();
14
clvInject.provider.on('accountsChanged', (accounts) => {
15
// do something
16
});
17
}tye
18
​
19
// send transaction
20
const send = (): void => {
21
const web3 = new Web3(clvInject.provider)
22
const accounts = await web3.eth.getAccounts();
23
const publicAddress = accounts[0]
24
web3.eth.sendTransaction({
25
from: publicAddress,
26
to: publicAddress,
27
value: web3.utils.toWei('0.01')
28
})
29
}
30
​
31
// eth_sign
32
const signMessage = (): void => {
33
const web3 = new Web3(clvInject.provider)
34
const accounts = await web3.eth.getAccounts();
35
const publicAddress = accounts[0]
36
// hex message
37
const message = '0x000000000000000000000000000000000000';
38
web3.currentProvider.send(
39
{
40
method: 'eth_sign',
41
params: [publicAddress, message],
42
jsonrpc: '2.0',
43
},
44
(err: Error, result: any) => {
45
// error handle
46
},
47
);
48
}
49
​
50
// personal message
51
const signPersonalMsg = async () => {
52
try {
53
const web3 = new Web3(clvInject.provider)
54
const accounts = await web3.eth.getAccounts();
55
const publicAddress = accounts[0]
56
const message = 'Example';
57
const hash = web3.utils.sha3(message);
58
const sig = await web3.eth.personal.sign(hash, publicAddress, '');
59
} catch (error) {
60
//error
61
}
62
}
63
​
64
// eth_signTypedData, eth_signTypedData_v3, eth_signTypedData_v4 are also supported
65
​
Copied!

Solana Blockchain Integration

CLV web wallet supports dApps on Solana. The sample code is as follows:
1
import CloverWebInjected from '@clover-network/web-wallet-sdk';
2
​
3
const clvInject = new CloverWebInjected({ zIndex: 99999 });
4
​
5
const initInjector = async () => {
6
await clvInject.init({
7
network: {
8
chainId: '0x1',
9
},
10
enableLogging: true,
11
});
12
13
await clvInject.solLogin();
14
}
15
​
16
const sendSolana = async () => {
17
const solAddress = await clvInject.clover_solana.getAccount();
18
const connection = new solanaWeb3.Connection(
19
solanaWeb3.clusterApiUrl('mainnet-beta'),
20
'confirmed',
21
);
22
const fromPubkey = new solanaWeb3.PublicKey(solAddress);
23
const toPubkey = new solanaWeb3.PublicKey(solAddress);
24
const transaction = new solanaWeb3.Transaction().add(
25
solanaWeb3.SystemProgram.transfer({
26
fromPubkey: fromPubkey,
27
toPubkey: toPubkey,
28
lamports: solanaWeb3.LAMPORTS_PER_SOL * 0,
29
}),
30
);
31
​
32
const block = await connection.getRecentBlockhash('max');
33
transaction.recentBlockhash = block.blockhash;
34
transaction.setSigners(fromPubkey);
35
​
36
const sss = await clvInject.clover_solana.signTransaction(transaction);
37
const rawTransaction = sss.serialize();
38
const a = await connection.sendRawTransaction(rawTransaction, {
39
skipPreflight: false,
40
preflightCommitment: 'single',
41
});
42
​
43
this.console('transaction hash:' + a);
44
}
45
​
46
const sendSolanaAll = async () => {
47
const solAddress = await clvInject.clover_solana.getAccount();
48
const connection = new solanaWeb3.Connection(
49
solanaWeb3.clusterApiUrl('mainnet-beta'),
50
'confirmed',
51
);
52
const fromPubkey = new solanaWeb3.PublicKey(solAddress);
53
const toPubkey = new solanaWeb3.PublicKey(solAddress);
54
const transaction = new solanaWeb3.Transaction().add(
55
solanaWeb3.SystemProgram.transfer({
56
fromPubkey: fromPubkey,
57
toPubkey: toPubkey,
58
lamports: solanaWeb3.LAMPORTS_PER_SOL * 0,
59
}),
60
);
61
​
62
const block = await connection.getRecentBlockhash('max');
63
transaction.recentBlockhash = block.blockhash;
64
transaction.setSigners(fromPubkey);
65
​
66
const sss = await clvInject.clover_solana.signAllTransactions([transaction]);
67
const rawTransaction = sss[0].serialize();
68
const a = await connection.sendRawTransaction(rawTransaction, {
69
skipPreflight: false,
70
preflightCommitment: 'single',
71
});
72
​
73
this.console('transaction hash:' + a);
74
}
75
​
Copied!