Skip to main content

Klaytn

getKlaytnSignedTransaction

The DCENT iOS SDK provides functions for signing transaction of coins.

This function is for:

  • .KLAYTN - klaytn (KLAY)
  • .KLAYTN_TESTNET - klaytn baobab (KLAYt)

Parameters

  • coinType: klaytn networks coin type
  • kalytnTransaction: (KlaytnTransaction)klaytn transaction parameter

class KlaytnTransaction

NameTypeDescription
addressPathStringsign key path for klaytn transaction
nonceStringaccount nonce for klaytn transaction
toStringrecipient's address of klaytn transaction
amountStringamount of ether to be sent. ( wei unit value )
gasLimitStringgas limit value of klaytn transaction
gasPriceStringgas price for klaytn transaction
dataStringtransaction data of klaytn transaction
chainIdStringchain id
fromString(optional) Signer's Address of klaytn transaction
tx_typeUInt8(optional) Type of klaytn transaction
The default value is KlaytnType.LEGACY.rawValue
fee_ratioUInt32(optional)Fee Ratio of klaytn transaction

enum KlaytnType

Defines Transaction type of Klaytn (refer to klaytn doc)

  • LEGACY
  • VALUE_TRANSFER
  • FEE_DELEGATED_VALUE_TRANSFER
  • FEE_DELEGATED_VALUE_TRANSFER_WITH_RATIO
  • VALUE_TRANSFER_MEMO
  • FEE_DELEGATED_VALUE_TRANSFER_MEMO
  • FEE_DELEGATED_VALUE_TRANSFER_MEMO_WITH_RATIO
  • SMART_CONTRACT_DEPLOY
  • FEE_DELEGATED_SMART_CONTRACT_DEPLOY
  • FEE_DELEGATED_SMART_CONTRACT_DEPLOY_WITH_RATIO
  • SMART_CONTRACT_EXECUTION
  • FEE_DELEGATED_SMART_CONTRACT_EXECUTION
  • FEE_DELEGATED_SMART_CONTRACT_EXECUTION_WITH_RATIO
  • CANCEL
  • FEE_DELEGATED_CANCEL
  • FEE_DELEGATED_CANCEL_WITH_RATIO
  • FEE_PAYER

Returns

  • result: (Bool) true if successful, false if error occurred
  • txData: signed transaction

Example

let klaytnTransaction : KlaytnTransaction = KlaytnTransaction(addressPath: "0", nonce: "", to: "", amount: "", gasLimit: "", gasPrice: "", data: "", chainId: 0)

// test data (legacy)
klaytnTransaction.addressPath = "m/44'/8217'/0'/0/0"
klaytnTransaction.nonce = "8"
klaytnTransaction.to = "0xe5c23dAa6480e45141647E5AeB321832150a28D4"
klaytnTransaction.amount = "60000000000000000"
klaytnTransaction.gasLimit = "25000"
klaytnTransaction.gasPrice = "25000000000"
klaytnTransaction.data = ""
klaytnTransaction.chainId = "1001"

DcentMgr.getKlaytnSignedTransaction(coinType:.KLAYTN, klaytnTransaction:klaytnTransaction){ (result, txData) in
print("Klaytn Transaction closure")
if result == false {
print("FAIL !!!")
}else{
print(txData)
}
}

getKlaytnBasedTokenTransaction

This Function for:

  • .KLAYTN_ERC20 - klaytn erc20 token (krc20)
  • .KRC20_TESTNET - klaytn testnet erc20 token

Parameters

  • coinType: klaytn networks coin type
  • tokenTransaction: (KlaytnTokenTransaction)klaytn token transaction parameter

class KlaytnTokenTransaction

NameTypeDescription
addressPathStringsign key path for klaytn transaction
nonceStringaccount nonce for klaytn transaction
toStringrecipient's address of klaytn transaction
amountStringamount of ether to be sent. ( wei unit value )
gasLimitStringgas limit value of klaytn transaction
gasPriceStringgas price for klaytn transaction
dataStringtransaction data of klaytn transaction
chainIdStringchain id
tokenNameStringtoken name of contract for KLAYTN_ERC20 transaction
decimalsUInt32decimals of contract for KLAYTN_ERC20 transaction
tokenSymbolStringsymbol of contract for KLAYTN_ERC20 transaction
fromString(optional) Signer's Address of klaytn transaction
tx_typeUInt8(optional) Type of klaytn transaction
The default value is KlaytnType.LEGACY.rawValue
fee_ratioUInt32(optional)Fee Ratio of klaytn transaction

Returns

  • result: (Bool) true if successful, false if error occurred
  • txData: signed transaction

Example

let krc20Transaction : KlaytnTokenTransaction = KlaytnTokenTransaction(addressPath: "", nonce: "", to: "", amount: "", gasLimit: "", gasPrice: "", data: "", chainId: 0, tokenName: "", decimals: 0, tokenSymbol: "")

// test data
krc20Transaction.addressPath = "m/44'/8217'/0'/0/0"
krc20Transaction.nonce = "6"
krc20Transaction.to = "0x92c1b39556d5322dac96e9e13d35a146297fcf43"
krc20Transaction.amount = "100000000"
krc20Transaction.gasLimit = "100000"
krc20Transaction.gasPrice = "25000000000"
krc20Transaction.data = "0xa9059cbb000000000000000000000000732E035fBdb9E5AB5Ef80c08f6aA081d029984dc"
krc20Transaction.chainId = "1001"
krc20Transaction.tx_type = KlaytnType.FEE_DELEGATED_SMART_CONTRACT_EXECUTION.rawValue
krc20Transaction.fromAddr = "0x689dfa2C77335722f333EeA102ba8A5E13d2AD1a"
krc20Transaction.fee_ratio = 0
krc20Transaction.tokenName = "BAOBABTOKEN"
krc20Transaction.decimals = 8
krc20Transaction.tokenSymbol = "BAO"

DcentMgr.getKlaytnBasedTokenTransaction(coinType: .KLAYTN_ERC20, tokenTransaction: krc20Transaction){ (result, txData) in
print("Klaytn token Transaction closure")
if result == false {
print("FAIL !!!")
}else{
print(txData)
}
}