caver-js
Last updated
Last updated
caver-js
is a JavaScript API library that allows developers to interact with a Klaytn node using a HTTP or Websocket connection. It is available on npm.
Complete implementation of Klaytn’s JSON-RPC client API over HTTP and Websocket
Support of Klaytn transaction, account, and account key types
JavaScript smart contract package to deploy and execute a smart contract on the Klaytn network
In-memory wallet for managing Klaytn accounts
Support of fee-delegation
Support of the Klaytn wallet key format
Encoding/decoding of a transaction object in RLP
Signing of a transaction object
Easy to port web3-js application to caver-js
Below are packages provided in caver-js
.
The error messages from Ethereum via web3.js are hardly figuring out where the error occurs. caver-js
improves the interface to catch error messages from Klaytn.
More details can be found in the value of txError
of the transaction receipt like the below:
Klaytn has a new gas price policy since the Magma hard fork which enabled the KIP-71.
Therefore, you need to set the gasPrice
logic differently when sending a transaction, depending on whether the hard fork is applicable or not.
Until the Magma hard fork, transactions on Klaytn have been subject to a "fixed gas price". Therefore, transactions with any other price submitted to the network are rejected. If gasPrice
is not defined when you sign or submit a transaction, caver-js uses caver.rpc.klay.getGasPrice RPC call to set the gas price.
After the Magma hard fork, Klaytn uses a "dynamic gas fee pricing mechanism". The gas price of the transaction should be higher than the base fee of the Klaytn network. If gasPrice
is not defined when you sign or submit a transaction, caver-js sets the gasPrice
field of the transaction using caver.rpc.klay.getGasPrice
.
caver-js provides various ways to set the gasPrice
. Ways to set the gasPrice
field when using caver-js are suggested below. The methods described here can be used regardless of the hard fork.
gasPrice
fieldIf you create an instance without defining the gasPrice
field, the gasPrice
field is automatically set when you call tx.sign
or tx.signAsFeePayer
to sign a transaction.
tx.fillTransaction
methodYou can use tx.fillTransaction
, a function that fills the optional fields of a transaction with appropriate values when they are omitted.
tx.suggestGasPrice
methodYou can set the gasPrice
with the result of tx.suggestGasPrice
which returns the recommended gas price.
For more information about the gas price, see Gas and Unit Price Overview The price of gas used in the network can be obtained by using caver.rpc.klay.getGasPrice.
caver-js GitHub repository
caver-js on npm