Re- Entrancy attack example given in video uses compiler 0.4.10 which won’t on latest compiler 0.8.5;
I could not able to solve the compilation error with the latest compiler 0.8.5, Could you please let me know why this error comes in the updated compiler & what was the workaround.
Note :- all code given in example have same compilation error, Please update the code.
pragma solidity 0.8.5;
contract SecCheck{
mapping(address=> uint)balance;
function deposit(uint _amt) public {
balance[msg.sender] += msg.value;
}
function getBalance() public returns (uint)
{
return address(this).balance;
}
function withdraw(uint _amt) public
{
uint Totalbal = balance[msg.sender];
require(msg.sender.call.value(Totalbal) ());
balance[msg.sender] = 0;
}
}
TypeError: Using “.value(…)” is deprecated. Use “{value: …}” instead.
–> SecurityChck.sol:19:17:
|
19 | require(msg.sender.call.value(Totalbal)());
| ^^^^^^^^^^^^^^^^^^^^^
TypeError: Wrong argument count for function call: 0 arguments given but expected 1. This function requires a single bytes argument. Use “” as argument to provide empty calldata.
–> SecurityChck.sol:19:17:
|
19 | require(msg.sender.call.value(Totalbal)());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: No matching declaration found after argument-dependent lookup.
–> SecurityChck.sol:19:9:
|
19 | require(msg.sender.call.value(Totalbal)());
| ^^^^^^^
Note: Candidate: function require(bool)
Note: Candidate: function require(bool, string memory)