#
Idena smart contractsNote: Currently only predefined smart contracts available (see below).
#
Gas and Transaction feeIn addition to transaction fee per byte a gas consumption has to be paid when a smart contract is called.
Transaction fee and gas charged when calling the following for smart contracts:
maxFee
parameter#
Maximum transaction fee maxFee
parameter must cover a sum of txFee
+gasCost
.
GasCost
is calculated as a total amount of gas consumed by the smart contract operations multiplied to the current GasPrice
.
You can use estimation methods to get an expected amount of gas that will be consumed by the smart contract:
Response example:
The maxFee
parameter can be omitted when calling estimation methods.
#
GasPriceGasPrice
is calculated automatically by the protocol. The minimum GasPrice
is: GasPrice
= 0.01
/NetworkSize
.
The bcn_feePerGas
method should be called to get the current GasPrice
.
Example:
#
Smart contract stakeIn order to deploy a new Idena smart contract stake must be locked. The amount
parameter has to be specified to lock the stake when DeployTx
transaction is called. If the specified amount is less than a minimum stake then error message will be returned.
Minimum smart contract stake is calculated as GasPrice
* 3000000
50% of the stake will be refunded to its creator once the smart contract is terminated.
#
Smart contract terminationTermination of the smart contract removes all smart contract data from the state. 50% of the stake is burnt. Another 50% of the stake transferred to the creator of the smart contract.
The contract might be terminated according to its internal rules.
For instance OracleVoting
smart contract can be terminated after a termination delay once the public voting is finished. Termination delay is proportional to the amount of coins blocked at the smart contract stake. Termination delay, days = round( (NetworkSize * Stake) ^ 1/3 )
#
Predefined smart contractsCurrently only predefined smart contracts available to deploy. You can find the code of the smart contracts here.
CodeHash
represents the algorithm of a predefined smart contract:
0x01
: TimeLock0x02
: OracleVoting (integrated into Idena app)0x03
: OracleLock0x04
: RefundableOracleLock0x05
: Multisig
#
Smart contracts transactionsDeployTx
: Create smart contractCallTx
: Call method of the smart contractTerminateTx
: Delete smart contract and refund 50% of the locked stake
#
Smart contracts transaction receiptTxReceipt
indicates result of mined smart contract transaction DeployTx
, CallTx
or TerminateTx
Contract
: address of the smart contractMethod
: called method of the smart contractSuccess
: whether transaction changed the state or notgasUsed
: amount of gas usedtxHash
: smart contract transaction hashError
: error textgasCost
: gas cost, iDNAtxFee
: transaction fee, iDNA
#
Smart contract addressYou can calculate the address of the smart contract before it will be deployed as following:
addr
: sender addressepoch
: epoch when the smart contract will be deployednonce
: nonce of the deploy transaction
Example: