Deploy Smart Contract

This page introduces how to send the transaction that deploys a smart contract to Klaytn with Wallet API.

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.

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.

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 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. In this example, the deploying account must directly pay the transaction fee for deploying the smart contract.

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.

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": "0x60806040526000805534801561001457600080fd5b50610116806100246000396000f3006080604052600436106053576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306661abd14605857806342cbb15c146080578063d14e62b81460a8575b600080fd5b348015606357600080fd5b50606a60d2565b6040518082815260200191505060405180910390f35b348015608b57600080fd5b50609260d8565b6040518082815260200191505060405180910390f35b34801560b357600080fd5b5060d06004803603810190808035906020019092919050505060e0565b005b60005481565b600043905090565b80600081905550505600a165627a7a7230582064856de85a2706463526593b08dd790054536042ef66d3204018e6790a2208d10029",
  "nonce": 0,
  "gasLimit": 1000000,
  "submit": true
}"
  • 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.

{
  "from": "0xa4068f0d4e4ffad5945824cddd748ba2dc450330",
  "gasLimit": 1000000,
  "gasPrice": "0x5d21dba00",
  "input": "0x60806040526000805534801561001457600080fd5b50610116806100246000396000f3006080604052600436106053576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306661abd14605857806342cbb15c146080578063d14e62b81460a8575b600080fd5b348015606357600080fd5b50606a60d2565b6040518082815260200191505060405180910390f35b348015608b57600080fd5b50609260d8565b6040518082815260200191505060405180910390f35b34801560b357600080fd5b5060d06004803603810190808035906020019092919050505060e0565b005b60005481565b600043905090565b80600081905550505600a165627a7a7230582064856de85a2706463526593b08dd790054536042ef66d3204018e6790a2208d10029",
  "nonce": 1,
  "rlp": "0x28f901aa018505d21dba00830f4240808094a4068f0d4e4ffad5945824cddd748ba2dc450330b9013a60806040526000805534801561001457600080fd5b50610116806100246000396000f3006080604052600436106053576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306661abd14605857806342cbb15c146080578063d14e62b81460a8575b600080fd5b348015606357600080fd5b50606a60d2565b6040518082815260200191505060405180910390f35b348015608b57600080fd5b50609260d8565b6040518082815260200191505060405180910390f35b34801560b357600080fd5b5060d06004803603810190808035906020019092919050505060e0565b005b60005481565b600043905090565b80600081905550505600a165627a7a7230582064856de85a2706463526593b08dd790054536042ef66d3204018e6790a2208d100298080f847f8458207f5a0c55cd386f8b6d4184db705800b40d3512d7d26dfbe4a07c3bbb87bda535dedb4a03b2a723c89f6de420d298a87076756efdb624818d604278afd34d5896566444e",
  "signatures": [
    {
      "R": "0xc55cd386f8b6d4184db705800b40d3512d7d26dfbe4a07c3bbb87bda535dedb4",
      "S": "0x3b2a723c89f6de420d298a87076756efdb624818d604278afd34d5896566444e",
      "V": "0x7f5"
    }
  ],
  "status": "Submitted",
  "transactionHash": "0xc8b00d7084f35bf6b4d7bc4ecb145e6b80c570b715309067eec003890cbb26ec",
  "typeInt": 40,
  "value": "0x0"
}

For details about this API, please visit here. For inquires about this document or KAS, please visit KAS Developer 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 Klaytn Node and pay the transaction fee for this. To call this API, you first need to create the Klaytn account who sends this transaction and the Klaytn 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.

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.

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": "0x60806040526000805534801561001457600080fd5b50610116806100246000396000f3006080604052600436106053576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306661abd14605857806342cbb15c146080578063d14e62b81460a8575b600080fd5b348015606357600080fd5b50606a60d2565b6040518082815260200191505060405180910390f35b348015608b57600080fd5b50609260d8565b6040518082815260200191505060405180910390f35b34801560b357600080fd5b5060d06004803603810190808035906020019092919050505060e0565b005b60005481565b600043905090565b80600081905550505600a165627a7a7230582064856de85a2706463526593b08dd790054536042ef66d3204018e6790a2208d10029",
  "nonce": 0,
  "gasLimit": 1000000,
  "submit": true,
  "feePayer": "0x85B98485444c89880cD9C48807CEF727C296F2da",
  "feeRatio": 10
}"
  • 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 Klaytn.

    • 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.

{
  "feePayer": "0xe8ab1729ab614551021cf5cc22c0e037f5a82930",
  "from": "0x9c56b45b7443bc73f47234199982481c64807f78",
  "gasLimit": 1000000,
  "gasPrice": "0x5d21dba00",
  "input": "0x60806040526000805534801561001457600080fd5b50610116806100246000396000f3006080604052600436106053576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306661abd14605857806342cbb15c146080578063d14e62b81460a8575b600080fd5b348015606357600080fd5b50606a60d2565b6040518082815260200191505060405180910390f35b348015608b57600080fd5b50609260d8565b6040518082815260200191505060405180910390f35b34801560b357600080fd5b5060d06004803603810190808035906020019092919050505060e0565b005b60005481565b600043905090565b80600081905550505600a165627a7a7230582064856de85a2706463526593b08dd790054536042ef66d3204018e6790a2208d10029",
  "nonce": 1,
  "rlp": "0x29f90208018505d21dba00830f42408080949c56b45b7443bc73f47234199982481c64807f78b9013a60806040526000805534801561001457600080fd5b50610116806100246000396000f3006080604052600436106053576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306661abd14605857806342cbb15c146080578063d14e62b81460a8575b600080fd5b348015606357600080fd5b50606a60d2565b6040518082815260200191505060405180910390f35b348015608b57600080fd5b50609260d8565b6040518082815260200191505060405180910390f35b34801560b357600080fd5b5060d06004803603810190808035906020019092919050505060e0565b005b60005481565b600043905090565b80600081905550505600a165627a7a7230582064856de85a2706463526593b08dd790054536042ef66d3204018e6790a2208d100298080f847f8458207f6a0f746de3b0f1d16feb43d81afd8fa2e015a361637b56154af98ea7771c49d51f6a0532d1e59d20dc70ebdec6b634036c3224b69ed078a95069c9fe023156a80119894e8ab1729ab614551021cf5cc22c0e037f5a82930f847f8458207f6a0a7ffcbb1fe73d40785b25f583f70b4cfcd344c29c19bdcb172f3595fc296953ba01067b482a1c70b40ff4049295e83673005dca1dd1588ffda604b6fb88a14a2a8",
  "signatures": [
    {
      "R": "0xf746de3b0f1d16feb43d81afd8fa2e015a361637b56154af98ea7771c49d51f6",
      "S": "0x532d1e59d20dc70ebdec6b634036c3224b69ed078a95069c9fe023156a801198",
      "V": "0x7f6"
    }
  ],
  "status": "Submitted",
  "transactionHash": "0x245545412546364e8a5381f5d7574c2fe58b0c9099d867a23e4fbab82239f836",
  "typeInt": 41,
  "value": "0x0"
}

“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 Developer 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 Klaytn Node and pay the transaction fee for this. To call this API, you first need to create an Account Pool and a Klaytn 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 Klaytn 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.

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.

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": "0x60806040526000805534801561001457600080fd5b50610116806100246000396000f3006080604052600436106053576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306661abd14605857806342cbb15c146080578063d14e62b81460a8575b600080fd5b348015606357600080fd5b50606a60d2565b6040518082815260200191505060405180910390f35b348015608b57600080fd5b50609260d8565b6040518082815260200191505060405180910390f35b34801560b357600080fd5b5060d06004803603810190808035906020019092919050505060e0565b005b60005481565b600043905090565b80600081905550505600a165627a7a7230582064856de85a2706463526593b08dd790054536042ef66d3204018e6790a2208d10029",
  "nonce": 0,
  "gasLimit": 1000000,
  "submit": true,
  "feeRatio": 10
}"
  • 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 Klaytn.

    • 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.

{
  "feePayer": "0x85b98485444c89880cd9c48807cef727c296f2da",
  "feeRatio": 10,
  "from": "0x9c56b45b7443bc73f47234199982481c64807f78",
  "gasLimit": 1000000,
  "gasPrice": "0x5d21dba00",
  "input": "0x60806040526000805534801561001457600080fd5b50610116806100246000396000f3006080604052600436106053576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306661abd14605857806342cbb15c146080578063d14e62b81460a8575b600080fd5b348015606357600080fd5b50606a60d2565b6040518082815260200191505060405180910390f35b348015608b57600080fd5b50609260d8565b6040518082815260200191505060405180910390f35b34801560b357600080fd5b5060d06004803603810190808035906020019092919050505060e0565b005b60005481565b600043905090565b80600081905550505600a165627a7a7230582064856de85a2706463526593b08dd790054536042ef66d3204018e6790a2208d10029",
  "nonce": 1,
  "rlp": "0x29f90208018505d21dba00830f42408080949c56b45b7443bc73f47234199982481c64807f78b9013a60806040526000805534801561001457600080fd5b50610116806100246000396000f3006080604052600436106053576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306661abd14605857806342cbb15c146080578063d14e62b81460a8575b600080fd5b348015606357600080fd5b50606a60d2565b6040518082815260200191505060405180910390f35b348015608b57600080fd5b50609260d8565b6040518082815260200191505060405180910390f35b34801560b357600080fd5b5060d06004803603810190808035906020019092919050505060e0565b005b60005481565b600043905090565b80600081905550505600a165627a7a7230582064856de85a2706463526593b08dd790054536042ef66d3204018e6790a2208d100298080f847f8458207f6a0f746de3b0f1d16feb43d81afd8fa2e015a361637b56154af98ea7771c49d51f6a0532d1e59d20dc70ebdec6b634036c3224b69ed078a95069c9fe023156a80119894e8ab1729ab614551021cf5cc22c0e037f5a82930f847f8458207f6a0a7ffcbb1fe73d40785b25f583f70b4cfcd344c29c19bdcb172f3595fc296953ba01067b482a1c70b40ff4049295e83673005dca1dd1588ffda604b6fb88a14a2a8",
  "signatures": [
    {
      "R": "0xf746de3b0f1d16feb43d81afd8fa2e015a361637b56154af98ea7771c49d51f6",
      "S": "0x532d1e59d20dc70ebdec6b634036c3224b69ed078a95069c9fe023156a801198",
      "V": "0x7f6"
    }
  ],
  "status": "Submitted",
  "transactionHash": "0x245545412546364e8a5381f5d7574c2fe58b0c9099d867a23e4fbab82239f836",
  "typeInt": 41,
  "value": "0x0"
}

“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 Developer forum.

Last updated