Before Getting Started

  • The x-chain-id value for calling the API is 8217 (Cypress) or 1001 (Baobab).
  • Essential parameters for calling APIs are described in individual examples.

Values that a user needs to enter for calling APIs will be represented with one pair of braces ({}). A user must enter the following values.

Item Description Note
chain-id 8217 or 1001 Cypress(Klaytn mainnet) or Baobab(Klaytn testnet
access-key-id Auth ID accessKeyId obtained from KAS Console > [Security] > [Credential]
secret-access-key Auth Password secretAccessKey obtained from KAS Console > [Security] > [Credential]
krn (optional) ID of Account Pool Unnecessary when using Default Account Pool

A KAS API Authentication Key (API Auth Key) provides access to all KAS services and all the rights to a Klaytn account which was created by calling Wallet API via this API Auth Key. The rights here include accessing and transferring all the assets (KLAY, etc.) of or sending a transaction from a Klaytn account. If you shared your API Auth Key with any unauthorized personnel, your Klaytn account could be compromised and might cause unwanted transaction execution.

danger

DO NOT share your API Auth Key (Secret AccessKey or Authorization) with any unauthorized personnel. DO PUT efforts necessary to keep your API Auth Key safe for the security of your KAS/Klaytn account.

Send Legacy Transaction

In Klaytn, a legacy account has a AccountKeyLegacy which is its public key and private key are bounded to each other because the public key was derived from the private key. This account can only "send KLAY, deploy, and execute smart contracts" (legacy transactions). For more details, refer to Legacy Transaction.

info

In KAS, the first Klaytn account will be created as a legacy account by default. To send multisig, data anchoring, and other transactions, the legacy account must be Updated to Another Account.

To send this transaction via KAS, the user must send the transaction using KAS to Klaytn Node and pay the transaction fee for this. To call the API, he/she must first create an Account Pool and account, and then select an account to use.

info

For details about KAS SDK (caver-js/caver-java extensions) installation and execution, please visit KAS SDK. For more details on creating an Account Pool, account, and selecting an account, refer to Getting Started.

API Request

Call the legacy transaction transmission API. You may use the REST API or KAS SDKs (caver-js, caver-java extensions) for this. The API Request/Response example below introduces how to send KLAY to another Klaytn account by transmitting a legacy transaction to Klaytn.

cURLJavaScriptJava
Copy
Copied
curl --location --request POST "https://wallet-api.klaytnapi.com/v2/tx/legacy" \
-u {access-key-id}:{secret-access-key} \
--header "x-chain-id: {chain-id}"
--data-raw "{
  "from": "",
  "value": "0x121111111111111111",
  "to": "0x5bb85d4032354E88020595AFAFC081C24098202e",
  "nonce": 0,
  "gas": 1000000,
  "submit": true
}"
Copy
Copied
const tx = {
  from: "0x602846DDC31F6Fc092edcF945565fBE9c48BdD7E",
  to: "0x76c6b1f34562ed7a843786e1d7f57d0d7948a6f1",
  value: 1,
  gas: 25000,
  submit: true,
};
const result = await caver.kas.wallet.requestLegacyTransaction(tx);
Copy
Copied
LegacyTransactionRequest request = new LegacyTransactionRequest();
request.setFrom("0x81bA6c299350719B18dFAEC38ba566fBd5Cd7202");
request.setTo("0x95E3Fd82eCd2b32Cae8618599971F5F47F4bC110");
request.setGas((long)25000);
request.setValue("0x1");
request.setSubmit(true);

TransactionResult result = caver.kas.wallet.requestLegacyTransaction(request);
System.out.println(result);

API Response

Here is a response of the legacy transaction transmission API.

cURLJavaScriptJava
Copy
Copied
{
  "from": "0x85b98485444c89880cd9c48807cef727c296f2da",
  "gas": 1000000,
  "gasPrice": "0x5d21dba00",
  "input": "0x",
  "nonce": 0,
  "rlp": "0xf870808505d21dba00830f424094a311e7022a4db250689c89d99848f74ea5098f7d89121111111111111111808207f5a03e7173bf7a303b4e1bb6f8723b494bcaa196cf7b9d7af18a22ceda7f2e9c9226a057bf51a5f52d900d58470f5e28f25881eb6d3837502ba0bab13f022398ddbc26",
  "signatures": [{}],
  "status": "Submitted",
  "to": "0xa311e7022a4db250689c89d99848f74ea5098f7d",
  "transactionHash": "0x433d70e6bdbce725ac9472e9fe1242fa0e5bdcd1b60fa21b3dcadf858055b47b",
  "typeInt": 0,
  "value": "0x121111111111111111"
}
Copy
Copied
TransactionResult {
  from: '0x602846ddc31f6fc092edcf945565fbe9c48bdd7e',
  gas: 25000,
  gasPrice: '0x5d21dba00',
  nonce: 0,
  rlp: '0xf866808505d21dba008261a89476c6b1f34562ed7a843786e1d7f57d0d7948a6f101808207f6a033f988dfbaa5492609f140aed291e304b76780b0dffe00b083eef9b8a2a03098a037e50158ac76693abd2d8a29b17a1ad4229d75bd9dfc1c5daf96d2aef598844d',
  typeInt: 0,
  input: '0x',
  signatures: [
    Signature {
      R: '0x33f988dfbaa5492609f140aed291e304b76780b0dffe00b083eef9b8a2a03098',
      S: '0x37e50158ac76693abd2d8a29b17a1ad4229d75bd9dfc1c5daf96d2aef598844d',
      V: '0x7f6'
    }
  ],
  status: 'Submitted',
  to: '0x76c6b1f34562ed7a843786e1d7f57d0d7948a6f1',
  transactionHash: '0xa3c30517f7d00774ea52760a87bbb98d2f6754ce1a1e0041765dd9a8086a557c',
  value: '0x1'
}
Copy
Copied
class TransactionResult {
    from: 0x81ba6c299350719b18dfaec38ba566fbd5cd7202
    gas: 25000
    gasPrice: 0x5d21dba00
    input: 0x
    nonce: 949
    rlp: 0xf8688203b58505d21dba008261a89495e3fd82ecd2b32cae8618599971f5f47f4bc11001808207f5a05434e573ae1dbf496806a8d5e8f090c15ee2de3b89e852577c835d04357b5ca3a0784296750de8130e75b7551f119f9650971932fb1efee1023e7858fbe7fe8ff0
    signatures: [class Signature {
        R: 0x5434e573ae1dbf496806a8d5e8f090c15ee2de3b89e852577c835d04357b5ca3
        S: 0x784296750de8130e75b7551f119f9650971932fb1efee1023e7858fbe7fe8ff0
        V: 0x7f5
    }]
    status: Submitted
    to: 0x95e3fd82ecd2b32cae8618599971f5f47f4bc110
    transactionHash: 0x7b78348d9c49d2a169e07efb8c39cde8bc06aa382017037ebe2de33debffd567
    typeInt: 0
    value: 0x1
    code: null
    message: null
    transactionId: null
    accountKey: null
}

For details about this API, please visit here. For inquires about this document or KAS, please visit KAS Developers Forum.

Get Transaction Execution Result by Transaction Hash

Enter transaction hash value and search the transaction execution result. status field of response indicates if the transaction execution is successful.

To call the API, he/she must first create an Account Pool and account, and then select an account to use.

info

For details about KAS SDK (caver-js/caver-java extensions) installation and execution, please visit KAS SDK. For more details on creating an Account Pool, account, and selecting an account, refer to Getting Started.

API Request

Call the transaction search API. You may use the REST API or KAS SDKs (caver-js, caver-java extensions) for this.

cURLJavaScriptJava
Copy
Copied
curl --location --request GET "https://wallet-api.klaytnapi.com/v2/tx/0x62cbe2b959dd80b2dae88ccac3caba51c056989d2cb00bf7b4136c4945cc4644" \
-u {access-key-id}:{secret-access-key} \
--header "x-chain-id: {chain-id}" \
Copy
Copied
const transactionHash =
  "0x00a2e38b03abe9aeb85d9baa82ca3b1d4d55a4c2b354dc67ab23b82420f470f6";
const result = await caver.kas.wallet.getTransaction(transactionHash);
Copy
Copied
String txHash = "0x00a2e38b03abe9aeb85d9baa82ca3b1d4d55a4c2b354dc67ab23b82420f470f6";
TransactionReceipt receipt = caver.kas.wallet.getTransaction(txHash);
System.out.println(receipt);
  • submit : If it is false, a transaction is not sent and the RLP of signed transaction and the transaction information are returned.

API Response

Here is a response of the transaction search API.

cURLJavaScriptJava
Copy
Copied
{
  "blockHash": "0x421648a9920d4f97e60dc1d93c62e2b0c2f3a8df5ddb79252ce693974ef7806c",
  "blockNumber": "0xba",
  "contractAddress": null,
  "from": "0x325dbaf78b393dc2115138c86a58f897ed413aff",
  "gas": "0xf4240",
  "gasPrice": "0x5d21dba00",
  "gasUsed": "0x5398",
  "hash": "0x62cbe2b959dd80b2dae88ccac3caba51c056989d2cb00bf7b4136c4945cc4644",
  "input": "0x6d656d6f",
  "logs": [],
  "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "nonce": "0x1",
  "senderTxHash": "0x62cbe2b959dd80b2dae88ccac3caba51c056989d2cb00bf7b4136c4945cc4644",
  "signatures": [
    {
      "R": "0xf3d42d9f0d82f15a2acd18a5fbde0b1aff26936b89fec5151da59bdad4c4ddef",
      "S": "0x69a8b9319769c5dacffad42232d4d053d11722832169d71bca3f28b211f5f23d",
      "V": "0x7f6"
    }
  ],
  "status": "Committed",
  "to": "0x2f87ba64de5526f7880f21481effbf950f70005c",
  "transactionHash": "0x62cbe2b959dd80b2dae88ccac3caba51c056989d2cb00bf7b4136c4945cc4644",
  "transactionIndex": "0x0",
  "type": "TxTypeValueTransferMemo",
  "typeInt": 16,
  "value": "0x100"
}
Copy
Copied
TransactionReceipt {
  contractAddress: null,
  blockHash: '0xc344d42a58d4e78a1f845aac70beed0ee4c159efece62c8cbcd236690edc5439',
  blockNumber: '0x158bfb8',
  from: '0x7de4b173cd3ca86ff4ab4c669a7d8b36d82db3de',
  gas: '0x61a8',
  gasPrice: '0x5d21dba00',
  gasUsed: '0x5208',
  hash: '0x00a2e38b03abe9aeb85d9baa82ca3b1d4d55a4c2b354dc67ab23b82420f470f6',
  input: '0x',
  logs: [],
  logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
  nonce: '0x0',
  senderTxHash: '0x00a2e38b03abe9aeb85d9baa82ca3b1d4d55a4c2b354dc67ab23b82420f470f6',
  signatures: [
    Signature {
      R: '0x564e4a608fe6f2b9e344f648de929e8f6e60d6bafcd9a614a9dd71abce80a8ce',
      S: '0x4e787e2dbaec7dd0a60040af9350ce571fa452fb3756d2774ac89aade836ff4e',
      V: '0x7f5'
    }
  ],
  status: 'Committed',
  to: '0x76c6b1f34562ed7a843786e1d7f57d0d7948a6f1',
  transactionHash: '0x00a2e38b03abe9aeb85d9baa82ca3b1d4d55a4c2b354dc67ab23b82420f470f6',
  transactionIndex: '0x0',
  type: 'TxTypeLegacyTransaction',
  typeInt: 0,
  value: '0x1'
}
Copy
Copied
class TransactionReceipt {
    blockHash: 0xc344d42a58d4e78a1f845aac70beed0ee4c159efece62c8cbcd236690edc5439
    blockNumber: 0x158bfb8
    from: 0x7de4b173cd3ca86ff4ab4c669a7d8b36d82db3de
    gas: 0x61a8
    gasPrice: 0x5d21dba00
    gasUsed: 0x5208
    hash: 0x00a2e38b03abe9aeb85d9baa82ca3b1d4d55a4c2b354dc67ab23b82420f470f6
    input: 0x
    logs: []
    logsBloom: 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    nonce: 0x0
    senderTxHash: 0x00a2e38b03abe9aeb85d9baa82ca3b1d4d55a4c2b354dc67ab23b82420f470f6
    signatures: [class Signature {
        R: 0x564e4a608fe6f2b9e344f648de929e8f6e60d6bafcd9a614a9dd71abce80a8ce
        S: 0x4e787e2dbaec7dd0a60040af9350ce571fa452fb3756d2774ac89aade836ff4e
        V: 0x7f5
    }]
    status: Committed
    to: 0x76c6b1f34562ed7a843786e1d7f57d0d7948a6f1
    transactionHash: 0x00a2e38b03abe9aeb85d9baa82ca3b1d4d55a4c2b354dc67ab23b82420f470f6
    transactionIndex: 0x0
    type: TxTypeLegacyTransaction
    typeInt: 0
    value: 0x1
    contractAddress: null
    codeFormat: null
    feePayer: null
    feePayerSignatures: null
    humanReadable: null
}
info

"typeInt" variable is a value for identifying the transaction type. For details about the types of transactions, please visit here.

For details about this API, please visit here. For inquires about this document or KAS, please visit KAS Developers Forum.