Unable to match calculated “gas used” value using Solidity IDE to the etherscan explorer “Gas Used By Transaction”
I am trying find the gas used by the transaction when a method is clicked in the remix solidity IDE. my code is as below. Value I am getting in the gasUsed variable is different to the value that is being shown on the etherscan explorer for this transaction. It would be helpful if someone helps me in correcting my code.
pragma solidity ^0.4.22;
contract id
uint public id;
uint public senderValue;
uint256 public gasUsed;
constructor() public
senderValue= msg.sender;
function setId(uint _id) public
uint256 gasInitial = gasleft();
id= _id;
setGasUsed(gasInitial - gasleft());
function setGasUsed(uint256 _gasUsed) private
gasUsed = _gasUsed;
ethereum solidity remix etherscan
add a comment |
I am trying find the gas used by the transaction when a method is clicked in the remix solidity IDE. my code is as below. Value I am getting in the gasUsed variable is different to the value that is being shown on the etherscan explorer for this transaction. It would be helpful if someone helps me in correcting my code.
pragma solidity ^0.4.22;
contract id
uint public id;
uint public senderValue;
uint256 public gasUsed;
constructor() public
senderValue= msg.sender;
function setId(uint _id) public
uint256 gasInitial = gasleft();
id= _id;
setGasUsed(gasInitial - gasleft());
function setGasUsed(uint256 _gasUsed) private
gasUsed = _gasUsed;
ethereum solidity remix etherscan
add a comment |
I am trying find the gas used by the transaction when a method is clicked in the remix solidity IDE. my code is as below. Value I am getting in the gasUsed variable is different to the value that is being shown on the etherscan explorer for this transaction. It would be helpful if someone helps me in correcting my code.
pragma solidity ^0.4.22;
contract id
uint public id;
uint public senderValue;
uint256 public gasUsed;
constructor() public
senderValue= msg.sender;
function setId(uint _id) public
uint256 gasInitial = gasleft();
id= _id;
setGasUsed(gasInitial - gasleft());
function setGasUsed(uint256 _gasUsed) private
gasUsed = _gasUsed;
ethereum solidity remix etherscan
I am trying find the gas used by the transaction when a method is clicked in the remix solidity IDE. my code is as below. Value I am getting in the gasUsed variable is different to the value that is being shown on the etherscan explorer for this transaction. It would be helpful if someone helps me in correcting my code.
pragma solidity ^0.4.22;
contract id
uint public id;
uint public senderValue;
uint256 public gasUsed;
constructor() public
senderValue= msg.sender;
function setId(uint _id) public
uint256 gasInitial = gasleft();
id= _id;
setGasUsed(gasInitial - gasleft());
function setGasUsed(uint256 _gasUsed) private
gasUsed = _gasUsed;
ethereum solidity remix etherscan
ethereum solidity remix etherscan
asked Nov 13 '18 at 5:10
user7481861user7481861
123
123
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
The value of "gas used" in remix IDE is Execution Cost and the value of "Gas Used By Transaction" in etherscan is "Transaction cost".
Execution Costs are based on the cost of computational operations which are executed as a result of the transaction.
Transaction Costs are always based on the cost of which type of data you will send to blockchain. This depends on,
- base cost of transaction (21000 gas)
- the cost of a contract deployment (32000 gas)
- the cost for every zero byte of data or code for a transaction.
- the cost of every non-zero byte of data or code for a transaction.
You can understand easily by this image
Hope this answer clear your doubt.
I got it. So is it possible to get the value of transaction cost in the remix code anyhow?
– user7481861
Nov 13 '18 at 14:22
No, There is no way to get transaction cost through remix code, you can only get transaction cost after contract deployed.
– Mahesh Rajput
Nov 14 '18 at 5:09
add a comment |
Good question, I tested too. It means that, gasleft()
equals 20020 gas before executing gasUsed2 = gasleft();
. And after executing gasUsed2 = gasleft();
, gasleft()
= 0
test() transaction costs 61475 gas
gasUsed1 equals 40033 gas
gasUsed2 equals 20020 gas
pragma solidity ^0.4.22;
contract id
uint256 public gasUsed1;
uint256 public gasUsed2;
function test() public
gasUsed1 = gasleft();
gasUsed2 = gasleft();
yes exactly. did you get to know how to match it?
– user7481861
Nov 13 '18 at 14:19
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274209%2funable-to-match-calculated-gas-used-value-using-solidity-ide-to-the-etherscan%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The value of "gas used" in remix IDE is Execution Cost and the value of "Gas Used By Transaction" in etherscan is "Transaction cost".
Execution Costs are based on the cost of computational operations which are executed as a result of the transaction.
Transaction Costs are always based on the cost of which type of data you will send to blockchain. This depends on,
- base cost of transaction (21000 gas)
- the cost of a contract deployment (32000 gas)
- the cost for every zero byte of data or code for a transaction.
- the cost of every non-zero byte of data or code for a transaction.
You can understand easily by this image
Hope this answer clear your doubt.
I got it. So is it possible to get the value of transaction cost in the remix code anyhow?
– user7481861
Nov 13 '18 at 14:22
No, There is no way to get transaction cost through remix code, you can only get transaction cost after contract deployed.
– Mahesh Rajput
Nov 14 '18 at 5:09
add a comment |
The value of "gas used" in remix IDE is Execution Cost and the value of "Gas Used By Transaction" in etherscan is "Transaction cost".
Execution Costs are based on the cost of computational operations which are executed as a result of the transaction.
Transaction Costs are always based on the cost of which type of data you will send to blockchain. This depends on,
- base cost of transaction (21000 gas)
- the cost of a contract deployment (32000 gas)
- the cost for every zero byte of data or code for a transaction.
- the cost of every non-zero byte of data or code for a transaction.
You can understand easily by this image
Hope this answer clear your doubt.
I got it. So is it possible to get the value of transaction cost in the remix code anyhow?
– user7481861
Nov 13 '18 at 14:22
No, There is no way to get transaction cost through remix code, you can only get transaction cost after contract deployed.
– Mahesh Rajput
Nov 14 '18 at 5:09
add a comment |
The value of "gas used" in remix IDE is Execution Cost and the value of "Gas Used By Transaction" in etherscan is "Transaction cost".
Execution Costs are based on the cost of computational operations which are executed as a result of the transaction.
Transaction Costs are always based on the cost of which type of data you will send to blockchain. This depends on,
- base cost of transaction (21000 gas)
- the cost of a contract deployment (32000 gas)
- the cost for every zero byte of data or code for a transaction.
- the cost of every non-zero byte of data or code for a transaction.
You can understand easily by this image
Hope this answer clear your doubt.
The value of "gas used" in remix IDE is Execution Cost and the value of "Gas Used By Transaction" in etherscan is "Transaction cost".
Execution Costs are based on the cost of computational operations which are executed as a result of the transaction.
Transaction Costs are always based on the cost of which type of data you will send to blockchain. This depends on,
- base cost of transaction (21000 gas)
- the cost of a contract deployment (32000 gas)
- the cost for every zero byte of data or code for a transaction.
- the cost of every non-zero byte of data or code for a transaction.
You can understand easily by this image
Hope this answer clear your doubt.
answered Nov 13 '18 at 10:01
Mahesh RajputMahesh Rajput
2959
2959
I got it. So is it possible to get the value of transaction cost in the remix code anyhow?
– user7481861
Nov 13 '18 at 14:22
No, There is no way to get transaction cost through remix code, you can only get transaction cost after contract deployed.
– Mahesh Rajput
Nov 14 '18 at 5:09
add a comment |
I got it. So is it possible to get the value of transaction cost in the remix code anyhow?
– user7481861
Nov 13 '18 at 14:22
No, There is no way to get transaction cost through remix code, you can only get transaction cost after contract deployed.
– Mahesh Rajput
Nov 14 '18 at 5:09
I got it. So is it possible to get the value of transaction cost in the remix code anyhow?
– user7481861
Nov 13 '18 at 14:22
I got it. So is it possible to get the value of transaction cost in the remix code anyhow?
– user7481861
Nov 13 '18 at 14:22
No, There is no way to get transaction cost through remix code, you can only get transaction cost after contract deployed.
– Mahesh Rajput
Nov 14 '18 at 5:09
No, There is no way to get transaction cost through remix code, you can only get transaction cost after contract deployed.
– Mahesh Rajput
Nov 14 '18 at 5:09
add a comment |
Good question, I tested too. It means that, gasleft()
equals 20020 gas before executing gasUsed2 = gasleft();
. And after executing gasUsed2 = gasleft();
, gasleft()
= 0
test() transaction costs 61475 gas
gasUsed1 equals 40033 gas
gasUsed2 equals 20020 gas
pragma solidity ^0.4.22;
contract id
uint256 public gasUsed1;
uint256 public gasUsed2;
function test() public
gasUsed1 = gasleft();
gasUsed2 = gasleft();
yes exactly. did you get to know how to match it?
– user7481861
Nov 13 '18 at 14:19
add a comment |
Good question, I tested too. It means that, gasleft()
equals 20020 gas before executing gasUsed2 = gasleft();
. And after executing gasUsed2 = gasleft();
, gasleft()
= 0
test() transaction costs 61475 gas
gasUsed1 equals 40033 gas
gasUsed2 equals 20020 gas
pragma solidity ^0.4.22;
contract id
uint256 public gasUsed1;
uint256 public gasUsed2;
function test() public
gasUsed1 = gasleft();
gasUsed2 = gasleft();
yes exactly. did you get to know how to match it?
– user7481861
Nov 13 '18 at 14:19
add a comment |
Good question, I tested too. It means that, gasleft()
equals 20020 gas before executing gasUsed2 = gasleft();
. And after executing gasUsed2 = gasleft();
, gasleft()
= 0
test() transaction costs 61475 gas
gasUsed1 equals 40033 gas
gasUsed2 equals 20020 gas
pragma solidity ^0.4.22;
contract id
uint256 public gasUsed1;
uint256 public gasUsed2;
function test() public
gasUsed1 = gasleft();
gasUsed2 = gasleft();
Good question, I tested too. It means that, gasleft()
equals 20020 gas before executing gasUsed2 = gasleft();
. And after executing gasUsed2 = gasleft();
, gasleft()
= 0
test() transaction costs 61475 gas
gasUsed1 equals 40033 gas
gasUsed2 equals 20020 gas
pragma solidity ^0.4.22;
contract id
uint256 public gasUsed1;
uint256 public gasUsed2;
function test() public
gasUsed1 = gasleft();
gasUsed2 = gasleft();
answered Nov 13 '18 at 7:39
Egor ZarembaEgor Zaremba
48312
48312
yes exactly. did you get to know how to match it?
– user7481861
Nov 13 '18 at 14:19
add a comment |
yes exactly. did you get to know how to match it?
– user7481861
Nov 13 '18 at 14:19
yes exactly. did you get to know how to match it?
– user7481861
Nov 13 '18 at 14:19
yes exactly. did you get to know how to match it?
– user7481861
Nov 13 '18 at 14:19
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274209%2funable-to-match-calculated-gas-used-value-using-solidity-ide-to-the-etherscan%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown