The ethereum blockchain gives the developer the ability to write, compile and deploy blocks of code in order to extend the functionality of
an existing Ethereum Virtual Machine .
Solidity is currently the preferred programming language, however Serpent, LLL, and Mutan
are also viable options. Solidity source code files contain both the business model definition as well
as the processing logic. Here is an example of some solidity code.
Advantages of using Solidity for Ethereum Smart Contracts
many primate data types, looping control, arrays, mappings, and structures.
Using the truffle framework, unit testing is supported using both mocha and chai.
A solidity plug-in is available for both Microsoft Visual Studio and Visual Studio Code.
A browser based development environment is available using Remix and MetaMask.
How much will it cost to execute an Ethereum Smart Contract?
The answer to this question is both simple and complex. Ethereum smart contracts can contain function code that
simply reads data from the blockchain, as well having function code that modifies the blockchain in some way via
transactions. Smart contract code that is simply reading data from the blockchain requires no mining as the blockchain
in not being changed. These types of "read operations" require no ether gas and are "free". All transactions that
modify the blockchain in any way must be mined and therefore there is an associated ether gas cost. This ether gas
cost also applies to the deployment of the smart contract as it first needs to be written to the blockchain and then
The total cost of a transaction that creates a smart contract or executes a smart contract is based on
2 factors. The amount of ether gas that is consumed and the current ether gas price.
Total cost = GasUsed * GasPrice
GasPrice is dynamic and dictated by market conditions. Obtaining the current
GasPrice is fairly straightforward, just go to ETH Gas Station.
Determining GasUsed is much more challenging however.Each operation (OPCODE) in the EVM ( Ethereum Virtual Machine)
is assigned a number which represents how much gas it consumes when executed. To compute the total GasUsed value we sum up all the individual gas values
associated with the OPCODES that will appear in a given smart contract.The current list of OPCODES and associated gas values can be found here:
EVM OPCODES and Gas Values .
Let's start with a very simple contract that simply adds 2 number. Using the link above ( EVM OPCODES and Gas Values ),
we see that the ADD OPCODE consumes 3 gas. Also assuming our current gas price is 11 gwei (as listed ETH Gas Station ).
3 * 11 = 33 gwei
and converting this to ETH yields
33 gwei * (.000000001 gwei/per ETH )= .000000033 ETH
And if we assume that the current purchase price of Ethereum is $500.00 for 1 ETH, this translates to a real cost of $.0000165 for an ADD operation.
Although manually calculating the cost to execute a smart contract is possible,it becomes extremely difficult (or even
next to impossible) when the smart contract code becomes more complex and looping and iterative logic is present.
Here is some sample code that could be used with some modifications that would allow the smart contract developer to determine the
total gas required cost for a specific function.