NFT Series

Utility NFT: how to prove ownership

Paolo Servillo
Coinmonks

--

Photo by Dayne Topkin on Unsplash

Imagine that I’m a happy owner of an NFT.
Done?
Ok!

Now, I can prove to anyone that I am the holder of a unique cryptographical asset and, the blockchain guarantees for me.

But what can I do now with this superpower?

NFTs are tied to metadata; among them, there is also an URL to an image. So, in the so-called Crypto art world, I can certificate I’m the owner of that image. Fine! But this does not seem to be such a mighty power (also if in certain cases, the ownership is linked to the right of ownership and reproduction of that image).

How can I better exploit the proof of ownership of a certain NFT?

In my personal opinion, a good idea is to add utilities to an NFT.

There are many ways to add utility to an NFT, limited only by your imagination, it’s less about the technology itself, and more about the application of that technology.

So, for example, if I prove I’m the owner of an NFT I could:

and more other stuff, for example, gain access to exclusive experiences like concerts, exposures, events and so on.

This sounds more exciting to me!

In this situation, the ownership verification process of an NFT plays a central role.

At first glance, this might seem simple as the wallet address of an NFT holder is publically available on the blockchain, but the actual question is: “how can I prove that I’m the owner of the private key controlling that wallet?”.

A simplified process is shown below.

Here:

  • the User asks a verifier for an exclusive service allowed only to the owner of a certain NFT,
  • the Verifier generates a disposable token (that can have an expiration time or can only be used once) and sends a message to the User with:
    –the created token,
    –the id of the NFT that allows access to the requested service (also the ERC721 contract address and other information should be specified, but this is a simplified schema)
  • the User signs the message with his wallet and sends the message and signature to the Verifier,
  • the Verifier:
    –checks the token validity,
    –verifies the signature,
    –resolves the address of the User from the signature,
    –asks the Blockchain who is the owner of the NFT with id “nft_id”,
  • if the owner's address matches the User's address, the service is allowed.

The signature of the Verifier’s message guarantees that the User is who he claims to be, while the Blockchain certificates who is the owner of the utility NFT.

This process can be implemented simply with Javascript and ethers library.

The User side

To sign the message, the User needs an ethers Signer.

There are standard ways of managing a signer, in a hardhat development environment for example:

const [owner, userWallet] = await ethers.getSigners();

Below, is an example message from the Verifier :

const message = {
token: ‘1234567890987654321’,
network: ‘goerli’,
chainid: 5,
contract: ‘0x4F002457c944935596fFbE2F737C1550a0B4476f’,
nft_id: 42
};

To obtain the signature:

const signature = await userWallet.signMessage(JSON.stringify(message));

The Verifier side

To verify the signature, the ethers.utils.verifyMessage function can be used. This function returns the address of the account that signed the message to generate that signature (to better understand, also if the message has been tampered with, the function returns an address, but an address different from the one who actually signed the message).

const userAddress = await ethers.utils.verifyMessage(JSON.stringify(message), signature)

Now, the Verifier has to check the owner of the NFT with id “nft_id”.

const contract = await hre.ethers.getContractAt(“MyContract”, ‘0x4F002457c944935596fFbE2F737C1550a0B4476f’);
const realOwner = await contract.ownerOf(42);
expect(userAddress).to.equal(realOwner);

Read more from the NFT Series.

New to trading? Try crypto trading bots or copy trading

--

--

Paolo Servillo
Coinmonks

Blockchain technologies lover, Artificial Intelligence fervent advocate, Quantum Computing passionate, Agent simulation delighted