Before Getting Started

  • The x-chain-id value for calling the API is 8217 (Mainnet) or 1001 (Kairos).
  • 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 Kaia Mainnet or Kairos
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 Kaia account which was created by calling Wallet API via this API Auth Key. The rights here include accessing and transferring all the assets (KAIA, etc.) of or sending a transaction from a Kaia account. If you shared your API Auth Key with any unauthorized personnel, your Kaia 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/Kaia account.

Deploy Smart Contract: Direct Payment of Transaction Fee

To deploy a smart contract through KAS, the bytecode (input) has to be obtained by writing the smart contract for deploying using Solidity and compiling it with Solidity Compiler. For more details on how to compose and compile smart contracts with Solidity and obtain the bytecode, refer to the Followings. To deploy a smart contract to KAS, the user must send the transaction using KAS to Kaia 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. In this example, the deploying account must directly pay the transaction fee for deploying the smart contract.

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 smart contract deployment API. You may use the REST API or KAS SDKs (caver-js, caver-java extensions) for this.

cURLJavaScriptJava
Copy
Copied
curl --location --request POST "https://wallet-api.klaytnapi.com/v2/tx/contract/deploy" \
-u {access-key-id}:{secret-access-key} \
--header "x-chain-id: {chain-id}" \
--header "Content-Type: application/json" \
--data-raw "{
  "from": "0x5bb85d4032354E88020595AFAFC081C24098202e",
  "value": "0x0",
  "input": "0x60806040526000805534801561001457600080...",
  "nonce": 0,
  "gasLimit": 1000000,
  "submit": true
}"
Copy
Copied
const tx = {
  from: "0x48c08e034c4c9779800713A9ad5BA768dA196288",
  value: 0,
  input: "0x608060405234801561001057600080fd5b5061...",
  gas: 1000000,
  submit: true,
};
const result = await caver.kas.wallet.requestSmartContractDeploy(tx);
Copy
Copied
String input = "0x608060405234801561001057600080fd5b5061...";

ContractDeployTransactionRequest request = new ContractDeployTransactionRequest();
request.setFrom("0x81bA6c299350719B18dFAEC38ba566fBd5Cd7202");
request.setInput(input);
request.setGas(1500000L);
request.submit(true);

TransactionResult transactionResult = caver.kas.wallet.requestSmartContractDeploy(request);
System.out.println(transactionResult);
  • input : The bytecode of smart contract to be deployed. It can be obtained by compiling this smart contract that is written with Solidity using the Solidity compiler
  • 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 the response of the smart contract deployment API.

cURLJavaScriptJava
Copy
Copied
{
  "from": "0xa4068f0d4e4ffad5945824cddd748ba2dc450330",
  "gasLimit": 1000000,
  "gasPrice": "0x5d21dba00",
  "input": "0x60806040526000805534801561001457600080...",
  "nonce": 1,
  "rlp": "0x28f901aa018505d21dba00830f4240808094a4...",
  "signatures": [
    {
      "R": "0xc55cd386f8b6d4184db705800b40d3512d7d26dfbe4a07c3bbb87bda535dedb4",
      "S": "0x3b2a723c89f6de420d298a87076756efdb624818d604278afd34d5896566444e",
      "V": "0x7f5"
    }
  ],
  "status": "Submitted",
  "transactionHash": "0xc8b00d7084f35bf6b4d7bc4ecb145e6b80c570b715309067eec003890cbb26ec",
  "typeInt": 40,
  "value": "0x0"
}
Copy
Copied
TransactionResult {
  from: '0x48c08e034c4c9779800713a9ad5ba768da196288',
  gas: 1000000,
  gasPrice: '0x5d21dba00',
  nonce: 0,
  rlp: '0x28f905af808505d21dba00830f424080809448...',
  typeInt: 40,
  input: '0x608060405234801561001057600080fd5b5061...',
  signatures: [
    Signature {
      R: '0x75faf2c7bb6efee259d33e4716f3efcdfe41c2e18ae6a5b0cbd75d47e961e8cb',
      S: '0x3bf54cf9af8fb34a5166e3a46322b99400561b5994bdee3864c578181c9d93b',
      V: '0x7f5'
    }
  ],
  status: 'Submitted',
  transactionHash: '0x3db5f0e773fb11674d8cdbe41ab1a80f04f4c0c956f7e81793ecf43b65d254a1',
  value: '0x0'
}
Copy
Copied
class TransactionResult {
    from: 0x81ba6c299350719b18dfaec38ba566fbd5cd7202
    gas: 1500000
    gasPrice: 0x5d21dba00
    input: 0x608060405234801561001057600080fd5b5061...
    nonce: 942
    rlp: 0x28f905b18203ae8505d21dba008316e3608080...
    signatures: [class Signature {
        R: 0x4247b05acf22c5801bda55b4b08ee8863f90e8afb86ab4287453397ba7837841
        S: 0x71b9d7415ad7d13ca693aeb690022af7744f9d7624d36a03b3ebf9e460d3f207
        V: 0x7f5
    }]
    status: Submitted
    to: null
    transactionHash: 0xda42a7a3cecb7b37500903eb611fe3227777f2abb0c7ef6839755bf9b26b4428
    typeInt: 40
    value: 0x0
    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.

Deploy Smart Contract: Transaction Fee Delegation by User

To deploy a smart contract through KAS, the bytecode (input) has to be obtained by writing the smart contract for deploying using Solidity and compiling it with Solidity Compiler. For more details on how to compose and compile smart contracts with Solidity and obtain the bytecode, refer to the Followings. To deploy a smart contract to KAS, the user must send the transaction using KAS to Kaia Node and pay the transaction fee for this. To call this API, you first need to create the Kaia account who sends this transaction and the Kaia account who pays the transaction fee (fee-payer) in Account Pool and Fee Payer Account Pool, each. In this example, the fee payer account pays the transaction transmission fee, not the account who sends this transaction. For details about fee-delegation methods that KAS provides for you, please visit here.

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. For more details on creating an fee payer Account Pool, fee payer account, and selecting an fee payer account, refer to Getting Started.

API Request

Call smart contract deployment with fee delegation API. You may use the REST API or KAS SDKs (caver-js, caver-java extensions) for this.

cURLJavaScriptJava
Copy
Copied
curl --location --request POST "https://wallet-api.klaytnapi.com/v2/tx/fd-user/contract/deploy" \
-u {access-key-id}:{secret-access-key} \
--header "x-chain-id: {chain-id}" \
--header "Content-Type: application/json" \
--data-raw "{
  "from": "0x5bb85d4032354E88020595AFAFC081C24098202e",
  "value": "0x0",
  "input": "0x60806040526000805534801561001457600080...",
  "nonce": 0,
  "gasLimit": 1000000,
  "submit": true,
  "feePayer": "0x85B98485444c89880cD9C48807CEF727C296F2da",
  "feeRatio": 10
}"
Copy
Copied
const tx = {
  from: "0x48c08e034c4c9779800713A9ad5BA768dA196288",
  value: 0,
  input: "0x608060405234801561001057600080fd5b5061...",
  gas: 3000000,
  submit: true,
  feePayer: "0x44Ee3906a7a2007762E9d706dF6E4eF63FA1edA8",
  feeRatio: 99,
};
const result = await caver.kas.wallet.requestFDSmartContractDeployPaidByUser(
  tx
);
Copy
Copied
String input = "0x608060405234801561001057600080fd5b5061...";

FDUserContractDeployTransactionRequest request = new FDUserContractDeployTransactionRequest();
request.setFrom("0x81bA6c299350719B18dFAEC38ba566fBd5Cd7202");
request.setFeePayer("0x31d845Ac80A0B2a38f6267CabcF34F8fA9DcD2B7");
request.setInput(input);
request.setGas(1500000L);
request.setSubmit(true);

FDTransactionResult result = caver.kas.wallet.requestFDSmartContractDeployPaidByUser(request);
System.out.println(result);
  • input : The bytecode of smart contract to be deployed. It can be obtained by compiling this smart contract that is written with Solidity using the Solidity compiler
  • submit : If it is false, a transaction is not sent and the RLP of signed transaction and the transaction information are returned.
  • fee_payer : If a user uses a separate transaction fee-payer account, he/she provides the account address to this parameter. Do not use the "feePayer" parameter to make KAS pay for the transaction fee first.
  • feeRatio : The ratio (1%~99%) of the transaction fee that a feePayer pays. The remaining fees will be directly paid by the account ( from ) that sends transactions to Kaia.
    • This parameter is available for fee delegation through either a user fee-payer account or and KAS (KAS Global fee payer)

API Response

Here is the response of smart contract deployment with fee-delegation API.

cURLJavaScriptJava
Copy
Copied
{
  "feePayer": "0xe8ab1729ab614551021cf5cc22c0e037f5a82930",
  "from": "0x9c56b45b7443bc73f47234199982481c64807f78",
  "gasLimit": 1000000,
  "gasPrice": "0x5d21dba00",
  "input": "0x60806040526000805534801561001457600080...",
  "nonce": 1,
  "rlp": "0x29f90208018505d21dba00830f42408080949c...",
  "signatures": [
    {
      "R": "0xf746de3b0f1d16feb43d81afd8fa2e015a361637b56154af98ea7771c49d51f6",
      "S": "0x532d1e59d20dc70ebdec6b634036c3224b69ed078a95069c9fe023156a801198",
      "V": "0x7f6"
    }
  ],
  "status": "Submitted",
  "transactionHash": "0x245545412546364e8a5381f5d7574c2fe58b0c9099d867a23e4fbab82239f836",
  "typeInt": 41,
  "value": "0x0"
}
Copy
Copied
FDTransactionResult {
  feePayer: '0x44ee3906a7a2007762e9d706df6e4ef63fa1eda8',
  from: '0x48c08e034c4c9779800713a9ad5ba768da196288',
  gas: 3000000,
  gasPrice: '0x5d21dba00',
  nonce: 2,
  rlp: '0x2af9060e028505d21dba00832dc6c080809448...',
  typeInt: 42,
  input: '0x608060405234801561001057600080fd5b5061...',
  signatures: [
    Signature {
      R: '0x12473ce621702f01f3e7000f8951fed2f1ff8e9916ac4132a13d708cd7b18e79',
      S: '0x3444d46f44e1a151486d8ebb0f00e01be1f2a463d1e1ecb0473633e59732afcb',
      V: '0x7f5'
    }
  ],
  status: 'Submitted',
  transactionHash: '0xd82bce9453949667447c30f781f311c34818dc2b5f04e1feea253cb706fece0c',
  value: '0x0',
  feeRatio: 99
}
Copy
Copied
class FDTransactionResult {
    feePayer: 0x31d845ac80a0b2a38f6267cabcf34f8fa9dcd2b7
    from: 0x81ba6c299350719b18dfaec38ba566fbd5cd7202
    gas: 1500000
    gasPrice: 0x5d21dba00
    input: 0x608060405234801561001057600080fd5b5061...
    nonce: 943
    rlp: 0x29f9060f8203af8505d21dba008316e3608080...
    signatures: [class Signature {
        R: 0x68d5d1bb49197b6cb9a8f6f4719edba80c3d12f02c2561e48df87aa181bd15d6
        S: 0x51998e5d202c13a99fa628cb9f9603f8d95355493411d7ead29574ec452d4d4c
        V: 0x7f5
    }]
    status: Submitted
    to: null
    transactionHash: 0xb296e84a04f068c2a6098b459feaeecf5c7a44719b481371b9581bc86f32a2b7
    typeInt: 41
    value: 0x0
    feeRatio: null
    transactionId: null
    accountKey: 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.

Deploy Smart Contract: Transaction Fee Delegation by KAS

To deploy a smart contract through KAS, the bytecode (input) has to be obtained by writing the smart contract for deploying using Solidity and compiling it with Solidity Compiler. For more details on how to compose and compile smart contracts with Solidity and obtain the bytecode, refer to the Followings. To deploy a smart contract to KAS, the user must send the transaction using KAS to Kaia Node and pay the transaction fee for this. To call this API, you first need to create an Account Pool and a Kaia account who sends this transaction in that Account Pool. In this example, the KAS global fee payer account pays the transaction transmission fee, not the account who sends this transaction. This fee paid by KAS global fee payer instead of the Kaia account who sent a transaction will later be charged to your KAS account. For details about fee-delegation methods that KAS provides for you, please visit here.

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 smart contract deployment with KAS GlobalFeePayer fee delegation API. You may use the REST API or KAS SDKs (caver-js, caver-java extensions) for this.

cURLJavaScriptJava
Copy
Copied
curl --location --request POST "https://wallet-api.klaytnapi.com/v2/tx/fd/contract/deploy" \
-u {access-key-id}:{secret-access-key} \
--header "x-chain-id: {chain-id}" \
--header "Content-Type: application/json" \
--data-raw "{
  "from": "0x5bb85d4032354E88020595AFAFC081C24098202e",
  "value": "0x0",
  "input": "0x60806040526000805534801561001457600080...",
  "nonce": 0,
  "gasLimit": 1000000,
  "submit": true,
  "feeRatio": 10
}"
Copy
Copied
const tx = {
  from: "0x79d1Fa3e6a69F0b2662ebd885B3c85A055927A97",
  value: 0,
  input: "0x608060405234801561001057600080fd5b5061...",
  gas: 3000000,
  submit: true,
  feeRatio: 99,
};
const result =
  await caver.kas.wallet.requestFDSmartContractDeployPaidByGlobalFeePayer(tx);
Copy
Copied
String input = "0x608060405234801561001057600080fd5b5061...";

FDContractDeployTransactionRequest request = new FDContractDeployTransactionRequest();
request.setFrom("0x81bA6c299350719B18dFAEC38ba566fBd5Cd7202");
request.setInput(input);
request.setGas((long)1500000);
request.setSubmit(true);

FDTransactionResult result = caver.kas.wallet.requestFDSmartContractDeployPaidByGlobalFeePayer(request);
System.out.println(result);
  • input : The bytecode of smart contract to be deployed. It can be obtained by compiling this smart contract that is written with Solidity using the Solidity compiler
  • submit : If it is false, a transaction is not sent and the RLP of signed transaction and the transaction information are returned.
  • feeRatio : The ratio (1%~99%) of the transaction fee that a feePayer pays. The remaining fees will be directly paid by the account ( from ) that sends transactions to Kaia.
    • This parameter is available for fee delegation through either a user fee-payer account or and KAS (KAS Global fee payer)

API Response

Here is the response of smart contract deployment with KAS GlobalFeePayer fee-delegation API.

cURLJavaScriptJava
Copy
Copied
{
  "feePayer": "0x85b98485444c89880cd9c48807cef727c296f2da",
  "feeRatio": 10,
  "from": "0x9c56b45b7443bc73f47234199982481c64807f78",
  "gasLimit": 1000000,
  "gasPrice": "0x5d21dba00",
  "input": "0x60806040526000805534801561001457600080...",
  "nonce": 1,
  "rlp": "0x29f90208018505d21dba00830f42408080949c...",
  "signatures": [
    {
      "R": "0xf746de3b0f1d16feb43d81afd8fa2e015a361637b56154af98ea7771c49d51f6",
      "S": "0x532d1e59d20dc70ebdec6b634036c3224b69ed078a95069c9fe023156a801198",
      "V": "0x7f6"
    }
  ],
  "status": "Submitted",
  "transactionHash": "0x245545412546364e8a5381f5d7574c2fe58b0c9099d867a23e4fbab82239f836",
  "typeInt": 41,
  "value": "0x0"
}
Copy
Copied
FDTransactionResult {
  feePayer: '0x1b71a63903e35371e2fc41c6012effb99b9a2c0f',
  from: '0x79d1fa3e6a69f0b2662ebd885b3c85a055927a97',
  gas: 3000000,
  gasPrice: '0x5d21dba00',
  nonce: 0,
  rlp: '0x2af9060e808505d21dba00832dc6c080809479...',
  typeInt: 42,
  input: '0x608060405234801561001057600080fd5b5061...',
  signatures: [
    Signature {
      R: '0x33f3237671b96d7d696c4b8564a67e7c3cb7ccfd3d94443b1918415fef669318',
      S: '0x50392fe89f8a7a94d04b5743ace53dff67293b9dcb493c09e96e8820e251323',
      V: '0x7f5'
    }
  ],
  status: 'Submitted',
  transactionHash: '0x97907f5d8155dcad80a609cf73b4c66f9673d57b11f302537df4a34a10190f14',
  value: '0x0',
  feeRatio: 99
}
Copy
Copied
class FDTransactionResult {
    feePayer: 0x1b71a63903e35371e2fc41c6012effb99b9a2c0f
    from: 0x81ba6c299350719b18dfaec38ba566fbd5cd7202
    gas: 1500000
    gasPrice: 0x5d21dba00
    input: 0x608060405234801561001057600080fd5b5061...
    nonce: 944
    rlp: 0x29f9060f8203b08505d21dba008316e3608080...
    signatures: [class Signature {
        R: 0xeda7d98bfbd65a46af2f3d42051b8f12924f9e311a8a35db6514005e263a14b2
        S: 0x1be3033f985d1197931658a9ad764ac3c6bac57c00e032803561ab67ea9636a
        V: 0x7f6
    }]
    status: Submitted
    to: null
    transactionHash: 0x4f7ba50fc8a2a14ba8628abc013251bea39c32fd7fcd3837a0486601f6751165
    typeInt: 41
    value: 0x0
    feeRatio: null
    transactionId: null
    accountKey: 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.