> For the complete documentation index, see [llms.txt](https://docs.wepin.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wepin.io/en/widget-integration/web-javascript-sdk/provider/kaia-provider.md).

# Kaia Provider

You can interact with EVM-based blockchains using Ethers.js or Web3.js together with the Wepin Provider.

## Supported Networks

{% hint style="info" %}
Is the blockchain you need not listed? Please [contact the Wepin](https://wepinwallet.typeform.com/WEPIN-Wallet-EN) team for blockchain support.
{% endhint %}

<table><thead><tr><th width="172.33333333333331">Chain ID</th><th>Network Name</th><th>Network Variable</th><th></th></tr></thead><tbody><tr><td>8217</td><td>Kaia Mainnet</td><td>klaytn</td><td></td></tr><tr><td>1001</td><td>Kaia Kairos Testnet</td><td>klaytn-testnet</td><td></td></tr></tbody></table>

## Installation

{% tabs %}
{% tab title="npm" %}

```bash
npm install @wepin/provider-js
```

{% endtab %}

{% tab title="yarn" %}

```bash
yarn add @wepin/provider-js
```

{% endtab %}
{% endtabs %}

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.

<pre class="language-javascript"><code class="lang-javascript"><strong>// 1. Import the package
</strong>import { WepinProvider } from '@wepin/provider-js'
<strong>
</strong>// 2. Initialization
const WepinProvider = new WepinProvider({
    appId: 'your-wepin-app-id',
    appKey: 'your-wepin-api-key',
})
</code></pre>

## Initialization

Here's how to initialize the Wepin Provider.&#x20;

## init

```javascript
await wepinProvider.init(attributes?)
```

### **Parameters**

* `attributes` \<object> **optional**
  * `defaultLanguage`: 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**

```javascript
await wepinProvider.init({
    defaultLanguage: 'ko',
    defaultCurrency: 'KRW',
})
```

## isInitialized&#x20;

It checks if WepinProvider is initialized properly.

```javascript
wepinProvider.isInitialized()
```

### **Parameters**

* `<void>`

### **Return value**

* `<boolean>`\
  Returns `true` if init was successful, otherwise returns `false`.

### **Example**

```javascript
if(wepinProvider.isInitialized()) {
  console.log('wepinProvider is initialized!')
}
```

## changeLanguage

It allows changing the language and currency of the widget.

```javascript
wepinProvider.changeLanguage(attributes)
```

### **Parameters**

* `attributes` \<object>
  * `language` \<string>\
    It specifies the language to be displayed on the widget. Currently supported languages are `en` , `ko` and `ja`.
  * `currency` \<string>\
    It specifies the currency to be displayed on the widget. Currently supported currencies are `USD` , `KRW` and `JPY`.

### **Return value**

* \<boolean>\
  It returns `true` if the change was successful, otherwise returns `false`.

### **Example**

```javascript
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.

```jsx
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](#supported-networks)."

### **Return value**

* `Promise`\<BaseProvider> - A EIP-1193 provider

### **Example**

```javascript
const provider = await wepinProvider.getProvider('klaytn')
```

### finalize

It terminates the use of WepinProvider.

```javascript
wepinProvider.finalize()
```

### **Parameters**

* `<void>`

### **Return value**

* `<void>`

### **Example**

```javascript
wepinProvider.finalize()
```

***

### request

You can send JSON-RPC requests to interact with the Kaia blockchain.

{% hint style="info" %}
The **kaia prefix method** has been supported since version **0.0.31**.
{% endhint %}

#### 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**

```typescript
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**

<table><thead><tr><th width="300">TxType</th><th width="247">Support Fee Delegateed</th><th>Version</th></tr></thead><tbody><tr><td>TxTypeLegacy</td><td>false</td><td></td></tr><tr><td>TxTypeValueTransfer</td><td>true</td><td>≥ v.0.0.31</td></tr><tr><td>TxTypeValueTransferMemo</td><td>true</td><td>≥ v.0.0.31</td></tr><tr><td>TxTypeSmartContractExecution</td><td>true</td><td>≥ v.0.0.31</td></tr></tbody></table>

**Parameters**

{% tabs %}
{% tab title="TxTypeLegacy" %}
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. Use `0x` for standard transfers.
  {% endtab %}

{% tab title="TxTypeValueTransfer" %}
A transaction type used to transfer KLAY.

* `typeInt` \<number> - 8(TxTypeValueTransfer) or 9(TxTypeFeeDelegatedValueTransfer) or 10(TxTypeFeeDelegatedValueTransferWithRatio)
* `from` \<string> - The sender's account address. An error occurs if it differs from the actual signer.
* `to` \<string> - The recipient's address.
* `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).
* `feePayer` \<string> - The address covering the transaction fee (Required if `typeInt` is 9 or 10).
* `feeRatio` \<string> - Fee payer's coverage percentage (Hex string, 1-99). Required if `typeInt` is 10.
  {% endtab %}

{% tab title="TxTypeValueTransferMemo" %}
A transaction type used to transfer KLAY with a memo message.

* `typeInt` \<number> - 16(TxTypeValueTransfer) or 17(TxTypeFeeDelegatedValueTransfer) or 18(TxTypeFeeDelegatedValueTransferWithRatio)
* `from` \<string> - The sender's account address. An error occurs if it differs from the actual signer.
* `to` \<string> - The recipient's address.
* `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).
* `input` \<string> - The memo message to be sent along with the transaction (Hex string).
* `feePayer` \<string> - The address covering the transaction fee (Required if `typeInt` is 9 or 10).
* `feeRatio` \<string> - Fee payer's coverage percentage (Hex string, 1-99). Required if `typeInt` is 10.
  {% endtab %}

{% tab title="TxTypeSmartContractExecution" %}
A transaction type used to execute a smart contract.

* `typeInt` \<number> - 48(TxTypeValueTransfer) or 49(TxTypeFeeDelegatedValueTransfer) or 50(TxTypeFeeDelegatedValueTransferWithRatio)
* `from` \<string> - The sender's account address. An error occurs if it differs from the actual signer.
* `to` \<string> - The recipient's address.
* `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).
* `input` \<string> - The data to be sent along with the transaction (Hex string).
* `feePayer` \<string> - The address covering the transaction fee (Required if `typeInt` is 9 or 10).
* `feeRatio` \<string> - Fee payer's coverage percentage (Hex string, 1-99). Required if `typeInt` is 10.
  {% endtab %}
  {% endtabs %}

**Returns**

* `Promise<Object>`
  * `raw <string>` - Serialized transaction.
  * `tx <Object>` - Signed transaction object.

**Example**

<pre class="language-typescript"><code class="lang-typescript"><strong>const params = {
</strong>      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()
)
</code></pre>

***

#### 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.\
\&#xNAN;**`sendTransaction` does not support FeeDelegated transactions.**

**Supported Tx Type**

<table><thead><tr><th width="300">TxType</th><th>Version</th></tr></thead><tbody><tr><td>TxTypeLegacy</td><td></td></tr><tr><td>TxTypeValueTransfer</td><td>≥ v.0.0.31</td></tr><tr><td>TxTypeValueTransferMemo</td><td>≥ v.0.0.31</td></tr><tr><td>TxTypeSmartContractExecution</td><td>≥ v.0.0.31</td></tr></tbody></table>

**Parameters**

{% tabs %}
{% tab title="TxTypeLegacy" %}
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. Use `0x` for standard transfers.
  {% endtab %}

{% tab title="TxTypeValueTransfer" %}
A transaction type used to transfer KLAY.

* `typeInt` \<number> - 8
* `from` \<string> - The sender's account address. An error occurs if it differs from the actual signer.
* `to` \<string> - The recipient's address.
* `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).
  {% endtab %}

{% tab title="TxTypeValueTransferMemo" %}
A transaction type used to transfer KLAY with a memo message.

* `typeInt` \<number> - 16
* `from` \<string> - The sender's account address. An error occurs if it differs from the actual signer.
* `to` \<string> - The recipient's address.
* `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).
* `input` \<string> - The memo message to be sent along with the transaction (Hex string).
  {% endtab %}

{% tab title="TxTypeSmartContractExecution" %}
A transaction type used to execute a smart contract.

* `typeInt` \<number> - 48
* `from` \<string> - The sender's account address. An error occurs if it differs from the actual signer.
* `to` \<string> - The recipient's address.
* `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).
* `input` \<string> - The data to be sent along with the transaction (Hex string).
  {% endtab %}
  {% endtabs %}

**Returns**

* `Promise<string>` - Transaction hash.

**Example**

```typescript
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**

```typescript
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**

```typescript
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**

```typescript
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**

```typescript
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**

```typescript
const signature = await wepinProvider.request({
      method: 'kaia_signTypedData_v4',
      params: [signerAddress, msgParamsV4 ]
})
```

For more details on  Kaia network, please refer to the link below.

{% embed url="<https://docs.kaia.io/references/json-rpc/references/>" %}
