This is challenge number 2 from the EthereumHacker.com list of challenges. Before you can tackle any of the challenges, you first have to install and configure Metamask. If you have not already done so, please take a look at the basic configuration instructions at: EthereumHacker Challenge 1 – The Gala NFT

Our second challenge – Find The Whale:

Go to EthereumHacker.com and click on the second challenge: “Find The Whale

Your task:

You need to find the address of the wallet that holds the Gala NFT token with the ID 45.

Here is the contract address again: 0x484Ec30Feff505b545Ed7b905bc25a6a40589181

You need to write a smart contract in Remix and deploy it to the Goerli test network. In the Remix file explorer, right-click on the “contracts” folder and add a new file with the name: Whale.sol

Solving the challenge:

What do we know?

We know that our contract is of type ERC721 and we know the ID of the token for which we need to find the owner.

Let’s take a look at the interface of an ERC721 contract, maybe we can find a function that allows us to find the owner of a specific token ID.

So, let’s head over to the Github OpenZeppelin page for the ERC721 interface: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/IERC721.sol

There are a couple of events and various functions. The one that looks promising is the following:

function ownerOf(uint256 tokenId) external view returns (address owner);

We provide a token ID and the function returns the owner address – exactly what we are looking for. Head over to Etherscan: https://goerli.etherscan.io/address/0x484Ec30Feff505b545Ed7b905bc25a6a40589181#readContract

Click on “ownerOf“, enter 45 for the token ID and click “Query” You should get the following address: 0x123e710c69b6806ef32Cf52e49dCC5EEEc368a22

Yes, that’s the correct answer, but the challenge is slightly more complicated: We were asked to write a smart contract in Remix with a function that returns the correct address.

Writing the smart contract:

So, let’s do that. All we need to do is write a smart contract that calls the “ownerOf” function on the NFT Gala contract. To do that, we will import the OpenZeppelin ERC721 interface and cast the address of the Gala contract to the type of IERC721.

This is possible, because the Gala NFT contract inherits from the OpenZeppelin ERC721 contract, which in turn inherits from the IERC721 interface that contains the “ownerOf” function.

Copy/paste the following contract into the Whale.sol file in Solidity:

// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

import "@openzeppelin/contracts/token/ERC721/IERC721.sol";

contract FindWhaleAddress {

    address public NFTContractAddress;

    constructor (address _NFTContractAddress){
        NFTContractAddress = _NFTContractAddress;

    }

    function getOwnerAddress(uint _tokenId) public view returns (address) {
        return IERC721(NFTContractAddress).ownerOf(_tokenId);
    }
}

In Remix, under “ENVIRONMENT”, select “Injected Provider – Metamask“, next to the orange deploy button, copy/paste the address of the Gala NFT contract: 0x484Ec30Feff505b545Ed7b905bc25a6a40589181 and click the “Deploy” button.

After confirming the contract deployment transaction in Metamask, you should find an instance of the deployed contract in Remix. Provide 45 for the tokenID and click the “getOwnerAddress” button.

This should return the correct whale address, which is: 0x123e710c69b6806ef32Cf52e49dCC5EEEc368a22