Wallet Structure

The custodial wallet of Klaytn has the following structure.

  • Main Address
  • Fee Address
  • Child Address

TIP
A fee (KLAY) will be charged from the fee address when gathering.
However, the fee will be charged from the fee address only when the fee delegation feature is enabled when withdrawing.






Child Address

Generates child addresses by calling the Generate Child Address API. Generally, one child address is given to each end user. Generated child addresses can be checked from [Child Address Information] from the console or by calling the Access Child Address List API.

Response example

[
  {
    "address": "0x236c41418f0320DC7233C8c9dC99EEa5930341D9",
    "name": "test address 002"
  }
]





Deposit

Deposit Status

When an asset from the outside arrives at the main or a child address, Octet recognizes it as a deposit. However, the deposit is not finalized even if the deposit transaction is included in the blocks. Additional blocks must be generated to finalize(FINALIZED) the transaction to ensure the integrity of the transaction. When an asset is sent to a main or a child address but has not arrived, that transaction is not recognized. Therefore, there is no FAILED status for the deposit transaction.

Status nameDescription
UNFINALIZEDDeposit transaction is included in the blocks
FINALIZEDDeposit transaction is included in the blocks and the next block is generated

The number of blocks required to finalize the deposit is different depending on the network. Both testnet and mainnet require additional 1 blocks to finalize the transaction.

TestnetMainnet
1 block (about 1s)1 block (about 1s)


Deposit Confirmation

1. Checking from the Console

You can check the deposit status from [Transaction History] on the console. UNFINALIZED deposits are displayed as ‘Processing’, and FINALIZED deposits are displayed as ‘Completed’.


2. Checking with Webhooks

When a deposit is finalized to a main or a child address, a deposit webhook will be sent. You can check the deposit status from the received webhook. For more information about how to use webhooks and their data structure, check the 'Webhook' page.






Gathering

Gathering Process

Assets stored in child addresses don’t move to the main address unless gathering is requested. Therefore, gatherings should be made regularly to avoid a deficit in the main address.

When a gathering of a specific asset is requested, all KLAYs or tokens stored in every child address transfer to the main address. At this point, one transaction occurs per each child address. For example, when 10 child addresses store KLAYs, 10 transactions will occur in total.

At this point, the gathering will not be made if the assets to be gathered are less than the expected fees. Gathering process is as follows.

  1. Request gathering.
  2. Generate a transaction for each child addresses to be gathered.
  3. Calculates the optimal fees and propagates the transactions.
  4. Gathering is completed when transactions are confirmed in the blocks.


Gathering Fees

Gathering fees are deducted from the fee address using the Klaytn fee delegation feature. Therefore, you must store the fee (KLAY) in the fee address before the gathering to avoid a deficit in the main address.

When the balance of the fee address is insufficient, only the maximum possible transaction that could be generated will be gathered. For example, if a gathering has to be processed for 10 child addresses, and the fee address balance is only enough to generate five transactions, then only five addresses will be gathered and not the others.



Gathering Status

Gathering status can be specified into four statuses, depending on the gathering process. The asset stored in the child address is in AWAITING_GATHERING status.

When a gathering request is made and generated a gathering transaction, the asset status changes to GATHERING. When the transaction is included in the blocks, the status of the asset is processed to COMPLETED and finishes the gathering.

When a gathering is tried and failed, the status of the asset will be processed as GATHERING_FAILED. Assets with GATHERING_FAILED status are included in the gathering target again. When a gathering is tried but failed to generate a transaction due to insufficient fees, it remains in AWAITING_GATHERING status.

Status nameDescription
AWAITING_GATHERINGAwaiting gathering
GATHERINGGenerate gathering transaction
COMPLETEDComplete gathering transaction
GATHERING_FAILEDFailed gathering transaction


Gather

Transfers the assets stored in the child address to the main address. Gatherings can be processed by one of the following two methods.

1. Gathering from the Console

You can gather from Console - Select a wallet - [Gathering History]. Click the [Gather] button, check the assets and the amount to gather, then proceed with the gathering.


2. Gathering with API

The gathering will be processed by calling the Request Gathering API.

Response example

[
  {
    "success": true,
    "uuid": "97410344-a48b-4f7e-a1ee-2feff91bebaa",
    "childAddresses": [
      "0x42d0aAE9A2305D66d20bE4361535FdB44670F933"
    ]
  },
  {
    "success": false,
    "childAddresses": [
      "0x94c1e678705cA8FB2d5929B37d01aAb14ffA9D7d"
    ],
    "errorCode": "ERR_0420002",
    "errorMessage": "The amount to be gathered is less than the minimum amount to be gathered."
  }
]


Gathering Status Confirmation

1. Checking from the Console

You can check the gathering history from Select a wallet - [Gathering History] - [Gathering History].


2. Checking with API

You can check the gathering history by calling the Access Gathering Request Information API.

Response example

{
  "idx": 75,
  "status": "COMPLETED",
  "uuid": "061c3807-704a-477e-8a69-21bbfb71b16f",
  "createdDate": "2022-01-03T09:50:40.371Z",
  "modifiedDate": "2022-01-03T09:52:00.000Z",
  "coin": {
    "idx": 2,
    "symbol": "KLAY",
    "nameKo": "클레이튼",
    "nameEn": "Klaytn",
    "status": "ACTIVATED",
    "type": "DEFAULT",
    "contractAddress": null,
    "decimals": 18,
    "createdDate": "2021-09-20T07:41:22.042Z",
    "modifiedDate": "2021-12-23T07:07:48.272Z"
  },
  "feeInjectionTransaction": null,
  "feeInjectionFee": null,
  "gatheringTransaction": {
    "idx": 9013,
    "uuid": "78ac42ae-1624-48e1-a22e-b9f74a627934",
    "type": "GATHERING",
    "txid": "0xf51f75ca0276877d851af598d92e8bdab4d99d034b8c11ee967eaf38aad5f179",
    "fromAddress": "0x61Cb7bbc6Ca8FF2502ad7163059E57e962a1776B",
    "toAddress": "0x71b5De2970A32eEf6362AE7Bc3B73103b4392bB0",
    "amount": "0.00003700000000000000",
    "usedFee": "0.00002100000014700000",
    "nonce": 0,
    "blockHeight": "6135121",
    "serialized": null,
    "memo": null,
    "status": "FINALIZED",
    "outputIndex": null,
    "createdDate": "2022-01-03T09:51:00.797Z",
    "modifiedDate": "2022-01-03T09:52:00.000Z",
    "unfinalizedDate": "2022-01-03T09:52:00.000Z",
    "finalizedDate": "2022-01-03T09:52:00.000Z",
    "failedDate": null,
    "coin": {
      "idx": 2,
      "symbol": "KLAY",
      "nameKo": "클레이튼",
      "nameEn": "Klaytn",
      "status": "ACTIVATED",
      "type": "DEFAULT",
      "contractAddress": null,
      "decimals": 18,
      "createdDate": "2021-09-20T07:41:22.042Z",
      "modifiedDate": "2021-12-23T07:07:48.272Z"
    }
  },
  "gatheringFee": {
    "idx": 184,
    "gasLimit": "21000.00000000000000000000",
    "gasPrice": "2.00000000000000000000",
    "unit": "gwei",
    "createdDate": "2022-01-03T09:50:40.369Z",
    "modifiedDate": "2022-01-03T09:50:40.369Z"
  }
}

3. Checking with Webhooks

When the gathering to the main address is finished, a gathering webhook will be sent. You can check the gathering status from the webhook. For more information about how to use webhooks and their data structure, check the 'Webhook' page.






Withdrawal

Withdrawal Process

Assets must be withdrawn from the main address to transfer them from a custodial wallet to the outside. An asset cannot be transferred outside from the child address.

  1. Request withdrawal.
  2. Generate transaction.
  3. Calculates the optimal fees and propagates the transactions.
  4. Withdrawal is completed when the transactions are confirmed in the blocks.


Withdrawal Status

Unlike a deposit, a withdrawal is finalized(FINALIZED) at the moment when the transaction is included in the blocks.

Status nameDescription
AWAITING_DECISIONAwaiting withdrawal approval
REJECTEDWithdrawal is denied
AWAITING_WITHDRAWALApproved and awaiting withdrawal
PENDINGWithdrawal transaction is generated
FINALIZEDWithdrawal transaction is included in the blocks
FAILEDWithdrawal transaction failed


Withdrawal Fees

You need to choose whether to use fee delegation for withdrawals.


1. Using Fee Delegation

The withdrawal fee will be deducted from the fee address if the fee delegation feature is enabled. In this case, the fee address should have assets (KLAY) to pay the fee. Withdrawal will not proceed if the withdrawal fee is insufficient.


2. Not Using Fee Delegation

The withdrawal fee will be deducted from the main address if the fee delegation feature is disabled. Therefore, the main address should have assets (KLAY) to pay the fee. Withdrawal will not proceed if the withdrawal fee is insufficient.



Withdraw

You can request a withdrawal from the main address to the outside by calling the Request Withdrawal API. The uuid value will be returned when the withdrawal request is successful. The value can be used to access the withdrawal process.

Response example

{
  "uuid": "18012e3f-07f3-45ec-862b-f020c0ca935a"
}


Withdrawal Confirmation

1. Checking from the Console

You can check the withdrawal status from [Transaction History] on the console. AWAITING_WITHDRAWAL or PENDING withdrawals are displayed as ‘Processing’, and FINALIZED withdrawals are displayed as ‘Completed’.


2. Checking with API

You can check the progress of a specific withdrawal transaction by calling the Access Withdrawal Transaction Information API.

Response example

{
  "idx": 490,
  "uuid": "07efdcb2-b3fd-4fe7-bf47-c0b460b289e3",
  "fromAddress": "0x71b5De2970A32eEf6362AE7Bc3B73103b4392bB0",
  "toAddress": "0x295909dC67B76f936BD4119aDd877088602cCaD3",
  "amount": "2.00000000000000000000",
  "memo": null,
  "requestId": "25",
  "type": "API",
  "description": "",
  "requiredApprovalCount": 1,
  "useApiAutoApproval": true,
  "status": "SENT",
  "createdDate": "2022-01-25T09:25:02.383Z",
  "modifiedDate": "2022-01-25T09:25:10.000Z",
  "rejectedDate": null
}

3. Checking with Webhooks

When the withdrawal from the main address is finished, a withdrawal webhook will be sent. You can check the withdrawal status from the webhook. For more information about how to use webhooks and their data structure, check the Webhook page.






Balance Access Criteria

You can check the balance of the asset stored in a specific address by calling the Access Address Balance API. The accessed balances are specified into total balances and liquid balances.

  • Total balance is all assets with a confirmation of 1 or above.
  • Liquid balance refers to the assets that can be gathered or withdrawn. The liquid balance of a child address represents the assets that can be gathered, while the liquid balance of the main address represents the assets that can be withdrawn.





Fees

Estimated Fees

Estimated fees are calculated by multiplying the gas price’s FASTEST value and the gas limit. Octet sets the gas limit of KLAYTNs to 21,000. The gas limit for tokens is set to 300,000 since it varies depending on how the tokens are implemented. The gas limit is the maximum value, so the actual gas usage could be less than that, and the fees are charged for the actual gas usage.

Estimated Fees = Gas Limit x Gas Price

Transaction Fees

You can access the gas price in real-time by calling the Fee/Gas API. Fees charged for a transaction are calculated by multiplying the gas price’s FASTEST value and the amount of used gas.

Transaction Fees = Usage by Txn x Gas Price





Faucet

In the case of the testnet, you must obtain a testing KLAY from the faucet website and deposit it. When an actual KLAT is deposited in the testnet, it will not be recognized.