RareSkills Solidity Interview Question #27 Answered: How can an ERC1155 token be made into a non-fungible token?

Faybian Byrd
Coinmonks
2 min readFeb 20, 2024

--

This series will provide answers to the list of Solidity interview questions that were published by RareSkills..

Question #27 (Easy): How can an ERC1155 token be made into a non-fungible token?

Answer: An ERC1155 token can be made into a non-fungible token by ensuring that it’s token id has a maximum supply of one, which represents a unique asset. Also, a uri can be specified for the token id, which should contain the metadata for the token, such as, image url, attributes, and other properties. This will allow the token to function as a non-fungible token.

Demonstration:

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

import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";

contract MyNFT is ERC1155 {
uint256 public constant UNIQUE_TOKEN_ID = 1;
string public name;
string public symbol;

constructor() ERC1155("https://myapi.com/api/token/{id}.json") {
name = "My Unique NFT";
symbol = "MUNFT";

_mint(msg.sender, UNIQUE_TOKEN_ID, 1, "");
}

function uri(uint256 tokenId) override public pure returns (string memory) {
return string(
abi.encodePacked(
"https://myapi.com/api/token/",
tokenId,
".json"
)
);
}
}

Further Discussion:

The criteria for fungibility is as follows:

  • Fungible Tokens: Are interchangeable and identical tokens, meaning each token is the same as every other token. One unit of a fungible token has the same value and properties as another unit. Examples of fungible tokens include cryptocurrencies like Bitcoin and Ether.
  • Non-Fungible Tokens (NFTs): Are unique and cannot be exchanged on a one-to-one basis with another token because each has distinct characteristics. An NFT represents ownership or proof of authenticity of a unique item or piece of content, such as digital art, collectibles, or even real estate in virtual worlds.

Connect with me:

Previous articles:

Disclosure: Some content may have been generated with the help of artificial intelligence.

--

--

Faybian Byrd
Coinmonks

Senior Software Engineer, Full Stack/Frontend @Synapse Labs | Graduate - Advanced Solidity Bootcamp @ RareSkills. | Certified Solidity Developer (CSD)