Kaia Provider
You can interact with EVM-based blockchains using Ethers.js or Web3.js together with the Wepin Provider.
Supported Networks
8217
Kaia Mainnet
klaytn
1001
Kaia Kairos Testnet
klaytn-testnet
Installation
npm install @wepin/provider-js
Once the installation is complete, initialize the WepinProvider instance using the app ID and app key assigned after registering the app. This will enable the use of WepinProvider.
// 1. Import the package
import { WepinProvider } from '@wepin/provider-js'
// 2. Initialization
const WepinProvider = new WepinProvider({
appId: 'your-wepin-app-id',
appKey: 'your-wepin-api-key',
})
Initialization
Here's how to initialize the Wepin Provider.
init
await wepinProvider.init(attributes?)
Parameters
attributes
<object> optionaldefaultLanguage
: The language to be displayed on the widget (default:'ko'
) Currently, only'ko'
,'en'
and'ja'
are supported.defaultCurrency
: The currency to be displayed on the widget (default:'KRW'
) Currently, only'KRW'
'USD'
and'JPY'
are supported.
Return value
Promise
<void>
Example
await wepinProvider.init({
defaultLanguage: 'ko',
defaultCurrency: 'KRW',
})
isInitialized
It checks if WepinProvider is initialized properly.
wepinProvider.isInitialized()
Parameters
<void>
Return value
<boolean>
Returnstrue
if init was successful, otherwise returnsfalse
.
Example
if(wepinProvider.isInitialized()) {
console.log('wepinProvider is initialized!')
}
changeLanguage
It allows changing the language and currency of the widget.
wepinProvider.changeLanguage(attributes)
Parameters
attributes
<object>language
<string> It specifies the language to be displayed on the widget. Currently supported languages areen
,ko
andja
.currency
<string> It specifies the currency to be displayed on the widget. Currently supported currencies areUSD
,KRW
andJPY
.
Return value
<boolean> It returns
true
if the change was successful, otherwise returnsfalse
.
Example
if(wepinProvider.isInitialized()) {
console.log('wepinProvider is initialized!')
}
Methods
Methods can be used after initializing the Wepin Provider.
getProvider
It returns the provider for the specified network.
await wepinProvider.getProvider(network)
Parameters
network
<string> The Network Variable value for providers supported by Wepin, such as "klaytn" for Klaytn Mainnet, must be entered in lowercase. For the complete list, please refer to the "Supported Networks for Kaia Provider."
Return value
Promise
<BaseProvider> - A EIP-1193 provider
Example
const provider = await wepinProvider.getProvider('klaytn')
finalize
It terminates the use of WepinProvider.
wepinProvider.finalize()
Parameters
<void>
Return value
<void>
Example
wepinProvider.finalize()
request
You can send JSON-RPC requests to interact with the Kaia blockchain.
eth_accounts / klay_accounts / kaia_accounts
Connects to the Wepin wallet and requests the user's permission to share their account address. Once connected, the application can sign messages or request transactions.
Parameters
void
Returns
Promise<Array<string>>
- List of user addresses.
Example
const accounts = await wepinProvider.request({
method: 'kaia_accounts',
params: []
})
eth_signTransaction / klay_signTransaction / kaia_signTransaction
Constructs a transaction with the given parameters and signs it with the user's private key.
Supported Tx Type
TxTypeLegacy
false
TxTypeValueTransfer
true
≥ v.0.0.31
TxTypeValueTransferMemo
true
≥ v.0.0.31
TxTypeSmartContractExecution
true
≥ v.0.0.31
Parameters
Represents the legacy transaction type that existed in Kaia (Klaytn).
from
<string> - The sender's account address. An error occurs if it differs from the actual signer.to
<string> - The recipient's address (contract or regular account).gas
<string> - The maximum gas limit for transaction execution (Hex string).gasPrice
<string> - The gas price for the transaction (Hex string).value
<string> - The amount of KLAY to be transferred (Hex string).data
<string> - The contract execution data or empty value. Use0x
for standard transfers.
Returns
Promise<Object>
raw <string>
- Serialized transaction.tx <Object>
- Signed transaction object.
Example
const params = {
typeInt: 49, //TxTypeFeeDelegatedSmartContractExecution
from: senderAddress,
to: '0x4dbccb64e9f7b4df4263d8e3b93c89ae406fd8e5',
input: '0x45773e4e'
gas: '0x15f90',
gasPrice: '0x5d21dba00',
feePayer: feePayerAddress,
}
const {raw, tx} = await wepinProvider.request({
method: 'kaia_signTransaction',
params: [params]
})
const decodedTx = caver.transaction.decode(raw)
const signedTx = await caver.wallet.signAsFeePayer(
feePayerAddress,
decodedTx as FeeDelegatedTransaction
)
const txId = await caver.rpc.klay.sendRawTransaction(
signedTx.getRawTransaction()
)
eth_sendTransaction / klay_sendTransaction / kaia_sendTransaction
Constructs a transaction with the given parameters, signs it with the user's private key, and sends it to the network.
sendTransaction
does not support FeeDelegated transactions.
Supported Tx Type
TxTypeLegacy
TxTypeValueTransfer
≥ v.0.0.31
TxTypeValueTransferMemo
≥ v.0.0.31
TxTypeSmartContractExecution
≥ v.0.0.31
Parameters
Represents the legacy transaction type that existed in Kaia (Klaytn).
from
<string> - The sender's account address. An error occurs if it differs from the actual signer.to
<string> - The recipient's address (contract or regular account).gas
<string> - The maximum gas limit for transaction execution (Hex string).gasPrice
<string> - The gas price for the transaction (Hex string).value
<string> - The amount of KLAY to be transferred (Hex string).data
<string> - The contract execution data or empty value. Use0x
for standard transfers.
Returns
Promise<string>
- Transaction hash.
Example
const params = {
typeInt: 8, //TxTypeValueTransfer
from: senderAddress,
to: toAddress,
value: '0x1234'
gas: '0x15f90',
gasPrice: '0x5d21dba00'
}
const txId = await wepinProvider.request({
method: 'kaia_sendTransaction',
params: [params]
})
eth_sign / klay_sign / kaia_sign
Signs a message using the EIP-191 format.
Parameters
<array>
<string>
- Address<string>
- Message to sign
Returns
Promise<string>
- Signature (hex string)
Example
const message = 'Hello World'
const signature = await wepinProvider.request({
method: 'kaia_sign',
params: [signerAddress, message]
})
personal_sign
Signs a message using the EIP-191 format.
Parameters
<array>
<string>
- Address<string>
- Message to sign
Returns
Promise<string>
- Signature (hex string)
Example
const message = 'Hello World'
const signature = await wepinProvider.request({
method: 'personal_sign',
params: [signerAddress, message]
})
eth_signTypedData_v1 / klay_signTypedData_v1
Signs data in EIP-712 v1 format.
Parameters
<array>
<string>
- Address<string>
- Message to sign
Returns
Promise<string>
- Signature (hex string)
Example
const signature = await wepinProvider.request({
method: 'kaia_signTypedData_v1',
params: [signerAddress, msgParamsV1 ]
})
eth_signTypedData_v3 / klay_signTypedData_v3
Signs data in EIP-712 v3 format.
Parameters
<array>
<string>
- Address<string>
- Message to sign
Returns
Promise<string>
- Signature (hex string)
Example
const signature = await wepinProvider.request({
method: 'kaia_signTypedData_v3',
params: [signerAddress, msgParamsV3 ]
})
eth_signTypedData_v4 / klay_signTypedData_v4
Signs data in EIP-712 v4 format.
Parameters
<array>
<string>
- Address<string>
- Message to sign
Returns
Promise<string>
- Signature (hex string)
Example
const signature = await wepinProvider.request({
method: 'kaia_signTypedData_v4',
params: [signerAddress, msgParamsV4 ]
})
For more details on Kaia network, please refer to the link below.
Last updated
Was this helpful?