Porting from web3j
We made caver-java as similar as possible to web3j for portability. The below code snippets show how to port an application written in web3j to caver-java.
1
/* start a client */
2
Web3j web3 = Web3j.build(new HttpService(<endpoint>)); // Web3j
3
Caver caver = Caver.build(new HttpService(<endpoint>)); // caver-java
4
5
/* get nonce */
6
BigInteger nonce = web3j.ethGetTransactionCount(<address>, <blockParam>).send().getTransactionCount(); // Web3j
7
Quantity nonce = caver.klay().getTransactionCount(<address>, <blockParam>).send().getValue(); // caver-java
8
9
/* convert unit */
10
Convert.toWei("1.0", Convert.Unit.ETHER).toBigInteger(); // Web3j
11
Convert.toPeb("1.0", Convert.Unit.KLAY).toBigInteger(); // caver-java
12
13
/* generate wallet file */
14
WalletUtils.generateNewWalletFile(<password>, <filepath>); // Web3j
15
KlayWalletUtils.generateNewWalletFile(<address>, <password>, <filepath>); // caver-java
16
17
/* load credentials */
18
Credentials credentials = WalletUtils.loadCrendetials(<password>, <filepath>"); // Web3j
19
KlayCredentials credentials = KlayWalletUtils.loadCredentials(<password>, <filepath>); // caver-java
20
21
/* Value Transfer */
22
TransactionReceipt transactionReceipt = Transfer.sendFunds(...),send(); // Web3j
23
KlayTransactionReceipt.TransactionReceipt transactionReceipt = ValueTransfer.sendFunds().send(); // caver-java
Copied!
Last modified 6mo ago
Copy link