Why this transaction is revert?
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I want to guarantee that user has enough Eth to execute back()
.
When you set little amount of eth in msg.value
, there are no revert.
However, if you set almost of all Eth you have, the revert is occurred.
Even if you have enough Eth msg.value
+ Gas fee, the revert is occurred.
Why?
You can try this in Remix.
- Choose Environment
- Choose Account which has 100 Eth
- Set Value to 90 ether.
- Execute back and revert.
Why?
```solidity
pragma solidity ^0.4.24;
contract Back is Ownable
using SafeMath for uint;
modifier affordPay()
require(msg.sender.balance > msg.value, "You don't have enough eth!!");
_;
function back() external affordPay() payable
msg.sender.transfer(msg.value);
```
solidity remix
add a comment |Â
up vote
2
down vote
favorite
I want to guarantee that user has enough Eth to execute back()
.
When you set little amount of eth in msg.value
, there are no revert.
However, if you set almost of all Eth you have, the revert is occurred.
Even if you have enough Eth msg.value
+ Gas fee, the revert is occurred.
Why?
You can try this in Remix.
- Choose Environment
- Choose Account which has 100 Eth
- Set Value to 90 ether.
- Execute back and revert.
Why?
```solidity
pragma solidity ^0.4.24;
contract Back is Ownable
using SafeMath for uint;
modifier affordPay()
require(msg.sender.balance > msg.value, "You don't have enough eth!!");
_;
function back() external affordPay() payable
msg.sender.transfer(msg.value);
```
solidity remix
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I want to guarantee that user has enough Eth to execute back()
.
When you set little amount of eth in msg.value
, there are no revert.
However, if you set almost of all Eth you have, the revert is occurred.
Even if you have enough Eth msg.value
+ Gas fee, the revert is occurred.
Why?
You can try this in Remix.
- Choose Environment
- Choose Account which has 100 Eth
- Set Value to 90 ether.
- Execute back and revert.
Why?
```solidity
pragma solidity ^0.4.24;
contract Back is Ownable
using SafeMath for uint;
modifier affordPay()
require(msg.sender.balance > msg.value, "You don't have enough eth!!");
_;
function back() external affordPay() payable
msg.sender.transfer(msg.value);
```
solidity remix
I want to guarantee that user has enough Eth to execute back()
.
When you set little amount of eth in msg.value
, there are no revert.
However, if you set almost of all Eth you have, the revert is occurred.
Even if you have enough Eth msg.value
+ Gas fee, the revert is occurred.
Why?
You can try this in Remix.
- Choose Environment
- Choose Account which has 100 Eth
- Set Value to 90 ether.
- Execute back and revert.
Why?
```solidity
pragma solidity ^0.4.24;
contract Back is Ownable
using SafeMath for uint;
modifier affordPay()
require(msg.sender.balance > msg.value, "You don't have enough eth!!");
_;
function back() external affordPay() payable
msg.sender.transfer(msg.value);
```
solidity remix
solidity remix
edited 2 hours ago
Lauri Peltonen
3,6342320
3,6342320
asked 2 hours ago
R. M.
133
133
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
The type of check you are performing is not only useless but it's plain wrong.
When a user issues a transaction with 90 Ethers as value, the 90 Ethers (plus gas) is immediately deducted from the account. The 90 Ethers becomes then visible in address(this).balance
. Therefore, also, the sender's balance is also updated and can be seen with address(msg.sender).balance
- it will have about 9.9999 Ethers (10 minus tx costs).
So you don't need to check whether msg.value
has an "acceptable" value - it will always contain a value which the user already committed into the transaction. Only if the transaction reverts the value is returned to the sender.
> the 90 Ethers (plus gas) is immediately deducted from the account. I understand what is wrong. I'm completely misunderstood the payable transaction works. Thanks.
– R. M.
1 hour ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
The type of check you are performing is not only useless but it's plain wrong.
When a user issues a transaction with 90 Ethers as value, the 90 Ethers (plus gas) is immediately deducted from the account. The 90 Ethers becomes then visible in address(this).balance
. Therefore, also, the sender's balance is also updated and can be seen with address(msg.sender).balance
- it will have about 9.9999 Ethers (10 minus tx costs).
So you don't need to check whether msg.value
has an "acceptable" value - it will always contain a value which the user already committed into the transaction. Only if the transaction reverts the value is returned to the sender.
> the 90 Ethers (plus gas) is immediately deducted from the account. I understand what is wrong. I'm completely misunderstood the payable transaction works. Thanks.
– R. M.
1 hour ago
add a comment |Â
up vote
1
down vote
accepted
The type of check you are performing is not only useless but it's plain wrong.
When a user issues a transaction with 90 Ethers as value, the 90 Ethers (plus gas) is immediately deducted from the account. The 90 Ethers becomes then visible in address(this).balance
. Therefore, also, the sender's balance is also updated and can be seen with address(msg.sender).balance
- it will have about 9.9999 Ethers (10 minus tx costs).
So you don't need to check whether msg.value
has an "acceptable" value - it will always contain a value which the user already committed into the transaction. Only if the transaction reverts the value is returned to the sender.
> the 90 Ethers (plus gas) is immediately deducted from the account. I understand what is wrong. I'm completely misunderstood the payable transaction works. Thanks.
– R. M.
1 hour ago
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
The type of check you are performing is not only useless but it's plain wrong.
When a user issues a transaction with 90 Ethers as value, the 90 Ethers (plus gas) is immediately deducted from the account. The 90 Ethers becomes then visible in address(this).balance
. Therefore, also, the sender's balance is also updated and can be seen with address(msg.sender).balance
- it will have about 9.9999 Ethers (10 minus tx costs).
So you don't need to check whether msg.value
has an "acceptable" value - it will always contain a value which the user already committed into the transaction. Only if the transaction reverts the value is returned to the sender.
The type of check you are performing is not only useless but it's plain wrong.
When a user issues a transaction with 90 Ethers as value, the 90 Ethers (plus gas) is immediately deducted from the account. The 90 Ethers becomes then visible in address(this).balance
. Therefore, also, the sender's balance is also updated and can be seen with address(msg.sender).balance
- it will have about 9.9999 Ethers (10 minus tx costs).
So you don't need to check whether msg.value
has an "acceptable" value - it will always contain a value which the user already committed into the transaction. Only if the transaction reverts the value is returned to the sender.
answered 1 hour ago
Lauri Peltonen
3,6342320
3,6342320
> the 90 Ethers (plus gas) is immediately deducted from the account. I understand what is wrong. I'm completely misunderstood the payable transaction works. Thanks.
– R. M.
1 hour ago
add a comment |Â
> the 90 Ethers (plus gas) is immediately deducted from the account. I understand what is wrong. I'm completely misunderstood the payable transaction works. Thanks.
– R. M.
1 hour ago
> the 90 Ethers (plus gas) is immediately deducted from the account. I understand what is wrong. I'm completely misunderstood the payable transaction works. Thanks.
– R. M.
1 hour ago
> the 90 Ethers (plus gas) is immediately deducted from the account. I understand what is wrong. I'm completely misunderstood the payable transaction works. Thanks.
– R. M.
1 hour ago
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fethereum.stackexchange.com%2fquestions%2f61714%2fwhy-this-transaction-is-revert%23new-answer', 'question_page');
);
Post as a guest
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
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
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