I have posted a couple of minutes ago my first tutorial on Ethereum and Solidity develoment, I would now to explain one thing that, apparently, from what I have read online, many people can't understand, I myself took some time to get the hang of it. In old versions of Solidity (Ethereum's programming language) you used the keyword `constant` to indicate that the transaction would not change any state on the network, this means, it wouldn't have to be verified by the network. This meant that the transaction was very cheap to be executed, in comparisson with transactions that required a change of state of a contract or an address. The keyword `constant` has been abandoned on solidity 0.4.16 and replaced by the keyword `view` that represents the exact same thing but has a more intuitive name, so, the `view` does not write or change anything, but it does read from the network. The other read only keyword is `pure`, which represents functions that **do not write NOR READ** from the network. The `pure` keyword is the cheapest transaction you can have, even cheaper than the `view` Here is an example ``` pragma solidity ^0.5.0; contract firstClassContract{ uint private unsignedInteger = 5; function aPureFunction(uint newVariable) public pure returns(uint) { return newVariable*2; } function aViewFunction(uint newVariable) public view returns (uint){ return unsignedInteger*newVariable; } } ``` And now I am gonna call the aPureFunction with the argumento 5, making it multiply 5 by 2 and then call the aViewFunction with the argument 2, making it multiply 5 by 2 too  I did the same mathematical operation in both two, but look at the price cost difference on them!   The `pure` function costs almost half of the price of the view function because it does not fetch data from the contract variables
author | igormuba |
---|---|
permlink | ethereum-development-don-t-use-constant-use-view-and-pure |
category | ethereum |
json_metadata | {"tags":["ethereum","development","solidity","programming","dapps"],"image":["https://cdn.steemitimages.com/DQmPz8pKQdjQuJY19krcStqjNQJcwS4FYQZs5hJzrngzojq/image.png","https://cdn.steemitimages.com/DQmfJSe7uNqdkRnShfxouV9Xrvwvx1f7kzAvETfeKf5xeYt/image.png","https://cdn.steemitimages.com/DQmb25gVWass3yWSSQa3n31twEvoDBcZyG3kSvWrgpq6g3f/image.png"],"app":"steemit/0.1","format":"markdown"} |
created | 2018-12-31 00:07:27 |
last_update | 2018-12-31 00:07:27 |
depth | 0 |
children | 0 |
last_payout | 2019-01-07 00:07:27 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.079 HBD |
curator_payout_value | 0.012 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 2,141 |
author_reputation | 129,602,803,494,761 |
root_title | "Ethereum Development - Don't Use Constant, Use View And Pure" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 77,630,601 |
net_rshares | 189,204,805,732 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
arcange | 0 | 37,719,357,873 | 4% | ||
raphaelle | 0 | 2,196,975,691 | 4% | ||
snwolak | 0 | 2,829,727,726 | 50% | ||
manuel78 | 0 | 1,024,847,291 | 25% | ||
msp-lovebot | 0 | 60,515,993,299 | 10% | ||
riscoin | 0 | 1,627,636,939 | 35% | ||
pataty69 | 0 | 6,191,712,192 | 20% | ||
msp-brasil | 0 | 12,549,258,230 | 30% | ||
instaforex | 0 | 523,864,519 | 100% | ||
solominer | 0 | 1,677,821,681 | 5% | ||
socpublic | 0 | 523,960,180 | 100% | ||
zoraivanov92 | 0 | 516,909,104 | 100% | ||
missvega | 0 | 521,867,484 | 100% | ||
byblik1811 | 0 | 524,059,575 | 100% | ||
hackettm21 | 0 | 517,144,606 | 100% | ||
minasyandianna | 0 | 523,248,127 | 100% | ||
dashakarapetyan | 0 | 521,851,419 | 100% | ||
bndage | 0 | 523,438,732 | 100% | ||
marunkas20 | 0 | 516,580,691 | 100% | ||
hommike | 0 | 516,473,343 | 100% | ||
albinasamirova | 0 | 517,529,020 | 100% | ||
aboriginalbook | 0 | 517,508,177 | 100% | ||
wombtick | 0 | 517,831,910 | 100% | ||
timedouble | 0 | 517,728,082 | 100% | ||
warblingunchin | 0 | 517,764,889 | 100% | ||
berwynelbow | 0 | 521,649,011 | 100% | ||
valvebangers | 0 | 517,635,733 | 100% | ||
yieldingcoke | 0 | 521,821,782 | 100% | ||
lizakotova | 0 | 523,252,169 | 100% | ||
linashevchyk | 0 | 517,502,801 | 100% | ||
svetatamova | 0 | 524,378,397 | 100% | ||
denistolakov | 0 | 517,872,227 | 100% | ||
antonerganov | 0 | 517,855,358 | 100% | ||
kadaevrenat | 0 | 522,051,731 | 100% | ||
deniselatov | 0 | 517,947,589 | 100% | ||
oksanagancharova | 0 | 517,855,486 | 100% | ||
cogsenchant | 0 | 516,580,529 | 100% | ||
nebulabilled | 0 | 516,959,264 | 100% | ||
filletsslither | 0 | 517,883,973 | 100% | ||
startophat | 0 | 516,620,105 | 100% | ||
casecod | 0 | 516,998,653 | 100% | ||
feettool | 0 | 517,614,746 | 100% | ||
insidescraper | 0 | 516,870,548 | 100% | ||
diplute | 0 | 516,888,643 | 100% | ||
loathsomemaps | 0 | 518,271,897 | 100% | ||
huskyelectron | 0 | 517,872,932 | 100% | ||
scotsmenmixin | 0 | 521,958,504 | 100% | ||
sryimin88ik | 0 | 517,347,598 | 100% | ||
duarte9sousa | 0 | 17,192,123,799 | 18% | ||
isabelpereira | 0 | 870,584,424 | 4% | ||
bhaski | 0 | 1,678,495,243 | 20% | ||
pitondessert | 0 | 518,400,486 | 100% | ||
arkoseduration | 0 | 522,384,669 | 100% | ||
joiningagitated | 0 | 517,281,446 | 100% | ||
estoniancurry | 0 | 517,480,110 | 100% | ||
aridknowledge | 0 | 522,881,506 | 100% | ||
cutnur | 0 | 6,774,540 | 10% | ||
pashafeloff | 0 | 517,419,910 | 100% | ||
rozenbah | 0 | 517,718,987 | 100% | ||
chepmengeri | 0 | 521,728,486 | 100% | ||
maksimle | 0 | 517,519,334 | 100% | ||
roman.senchukov | 0 | 517,672,552 | 100% | ||
yulya.zaharova | 0 | 517,620,193 | 100% | ||
inns.shuvts | 0 | 517,726,334 | 100% | ||
perlov11 | 0 | 517,638,732 | 100% | ||
bosssko | 0 | 517,766,017 | 100% | ||
potex | 0 | 513,039,299 | 100% | ||
yyyz | 0 | 515,397,841 | 100% | ||
inrgerm | 0 | 518,924,572 | 100% | ||
japanesecliff | 0 | 522,331,882 | 100% | ||
ploverka | 0 | 522,747,205 | 100% | ||
sessionscells | 0 | 518,699,681 | 100% | ||
hostlerodd | 0 | 523,098,920 | 100% | ||
branchanus | 0 | 523,146,611 | 100% | ||
enchantingspica | 0 | 522,045,350 | 100% | ||
warningapple | 0 | 518,792,473 | 100% | ||
nikbutus89 | 0 | 519,106,106 | 100% | ||
ivan.maznichenko | 0 | 522,675,408 | 100% | ||
mark.nikolaychev | 0 | 522,810,424 | 100% | ||
sitemapmap | 0 | 522,702,323 | 100% | ||
pectoralwake | 0 | 518,754,487 | 100% | ||
moistcurse | 0 | 523,254,798 | 100% | ||
smellbaryon | 0 | 518,925,769 | 100% | ||
disksworthless | 0 | 518,815,636 | 100% | ||
acceptremove | 0 | 518,681,860 | 100% | ||
limitingexmoor | 0 | 518,867,747 | 100% | ||
beeseregister | 0 | 518,874,296 | 100% | ||
haumearook | 0 | 523,114,150 | 100% | ||
bootedchork | 0 | 523,154,968 | 100% | ||
retrievedfale | 0 | 522,928,356 | 100% | ||
alivesushi | 0 | 522,961,303 | 100% | ||
moodycoupling | 0 | 519,066,542 | 100% | ||
caelumgoppers | 0 | 519,144,623 | 100% | ||
earedfinalist | 0 | 518,972,292 | 100% | ||
coulombprincess | 0 | 523,082,502 | 100% | ||
biotuamascyha | 0 | 518,691,084 | 100% |