---
title: "Kazoku"
subtitle: "A 3-month NFT project completed in partnership with Virstate.io"
description: "A look back at Kazoku, an Ethereum NFT project: ERC721A mint contract, signature-based whitelist, metadata resolver, staking and automated deployment."
author: "Roman Gascoin"
date: 2023-03-04
lang: en
tags: ["Freelance","Web3","Docker","Solidity"]
canonical: https://rgascoin.fr/blog/kazoku/
---

# Kazoku

> A 3-month NFT project completed in partnership with Virstate.io
## Links

| Label | Link |
| --- | --- |
| Mint | [https://mint.nftkazoku.com/](https://mint.nftkazoku.com/) (the site is closed, but you can view the media at the bottom of the page) |
| Manager | [https://manager.nftkazoku.com/](https://manager.nftkazoku.com/) (the site is closed, but you can view the media at the bottom of the page) |
| OpenSea | [https://opensea.io/collection/the-kazokus](https://opensea.io/collection/the-kazokus) |
| Etherscan | [https://etherscan.io/address/0x60193d4ab61c2872caa509ee532f9db169730a46](https://etherscan.io/address/0x60193d4ab61c2872caa509ee532f9db169730a46) |
| Twitter | [https://twitter.com/KazokuNFT](https://twitter.com/KazokuNFT) |

---

## Project recap

> Kazoku is an NFT project started in January 2022. Its initial goal was to promote a web3 ecosystem integrated into [The Sandbox](https://www.sandbox.game/en/).

> Several features were developed for the project's benefit:
>
> - Smart contract for **minting**
> - Smart contract for **tokens**
> - Smart contract for a **marketplace**
> - Smart contract for a **staking system**
> - **Interface** to interact with each smart contract
> - **DAO** system (web2/web3)
> - Infrastructure for **automated deployment**

> The project took longer than planned to release, due to the communication **difficulties** inherent in this type of project.

> The **crypto crash** caused by LUNA occurred during the project's launch period, which greatly **slowed down sales**.

> The entire collection was **minted by the community** (~180 holders), but the mint price had to be significantly **reduced**.

---

## Key points of the project

### The mint contract

This is the **foundation** of any NFT project: a smart contract capable of issuing `non-fungible tokens`. Several standards exist, each with its **advantages** and **disadvantages**. The most well-known are ERC721, ERC721A, and ERC1155. For this project, the **ERC721A** from Azuki was chosen.

This implementation has the advantage of offering **multiple mints** at **low cost**, like ERC1155, while keeping the basic ERC721 implementation.

The implementation of the ERC721A contract used for the Kazoku project **differs** in **two ways**:

#### URL management

An **override** of the functions used to retrieve the URLs **pointing to the metadata** of the NFTs.

```javascript
function tokenURI(uint256 tokenId) public view override returns (string memory)
function _baseURI() internal view override returns (string memory)
```

The goal of this change is to display a so-called "placeholder" image before revealing the real designs to users.

#### Adding a signlist

Many NFT projects use a whitelist system to favor and reward certain members of their community. There are several ways to implement whitelists in Solidity, but the most optimized technique I have found to date is based on signing addresses.

1. An account A is used to sign the address of the buyer B.
2. The signature is sent as an argument when calling the mint function.
3. The smart contract uses the `recover` method to prove the authenticity of the signature based on the sender.

Here is an example of the function used to verify the validity of the signature:

```javascript
/**
* @dev Does the user is whitelisted.
* Return 1 for yes else 0.
*/
function isWhiteList(bytes calldata _signature, address _targetSigner) view internal returns (uint8) {
	if (_targetSigner == keccak256(abi.encodePacked(
			"\x19Ethereum Signed Message:\n32",
			bytes32(uint256(uint160(msg.sender)))
	)).recover(_signature)) {
		return 1;
	}
		return 0;
}
```

For more information, I talk about it [on my Instagram](https://www.instagram.com/p/Cb93bcYt1jt/).

### The resolver

When a third-party service wants to display the **visual representation of an NFT**, it must call the `tokenURI(uint256 tokenId)` function to obtain a URL where the **NFT information** is located, in JSON format most of the time.

Several services, such as [Pinata](https://www.pinata.cloud/), let you easily upload your metadata online. However, I am not a fan of these solutions because you are **no longer in control of your data**, some of these services are **paid**, and you depend on their **resilience**.

That's why I set up a **Python** application using **FastAPI** and the **Alchemy** API to create my own metadata resolver.

The `tokenURI` method of my smart contract redirects to this **microservice** running on one of my servers. I then use **Alchemy's** services to determine whether the requested NFT has already been **minted or not**. If it has, I return the corresponding **metadata**.

*[image: Alchemy dashboard showing a 100% success rate and 565 total requests over the last 24 hours]*

*Alchemy dashboard used to measure the usage of their API.*

And what about data decentralization?

This system has a flaw: the NFT metadata is stored on a **conventional** server. However, this is not a deal-breaker for this type of project.

- Images are stored on **IPFS**; only metadata such as the name, description and attributes is stored on the server.
- To ensure **data integrity**, the hashes of all the metadata are made **public** at the beginning of the sale, and a way to verify their validity is provided.
- The user always has the option to **freeze** their data via OpenSea.
- Most NFT projects wish to make some adjustments shortly after their release. This gives them a little more flexibility while staying in line with their community.

*[image: The $OHZ token, a blue coin engraved with the letters OHZ]*

### DApps and other features

This project is not **only about a mint contract**. In its initial version, a whole ecosystem of DApps was supposed to be deployed: a **staking** application, a **marketplace**, an **ERC20** token, and a **voting** system.

The ERC20 token, called **$OHZ**, could only be generated through the staking system. It was used to purchase items on the **marketplace**.

To regulate the number of tokens in circulation, the tokens spent on a marketplace purchase were **burned**.

The staking system is divided into two categories:

- Active staking: you need to **deposit** your NFT in a contract to generate rewards.
- Passive staking: you can simply **keep** your NFT to generate rewards.

*[image: Kazoku slide "Bonus synergy, Example 1 - Active" detailing how 5 Kazokus and 1 Genesis Kazoku generate 11,450 $OHZ]*

A **rigorous implementation** had to be put in place for this contract. Many parameters had to be taken into account, such as the faction of the NFT, its rarity, and whether the faction was in a winning period.

The **voting system** is more traditional: it relies on an API linked to an **RPC** to verify whether the user holds **NFTs from the collection**, and thus whether they are eligible to vote. Once a person has voted, their address is temporarily **blacklisted**.

This web2 system was chosen by the project managers to **avoid excessive gas fees** for user interactions and for the Kazoku ecosystem.

### Integration on a website

Two **Next.js** applications were deployed for the project: one to allow NFT minting, and another to let users interact with the **different DApps of the project**.

A web3 module allows **different wallet providers** to connect to the sites.

*[image: Wallet connection modal offering MetaMask, WalletConnect and Coinbase]*

*[image: WalletConnect wallet picker listing Ledger, Tokenary, Infinity Wallet and other wallets]*

*[image: WalletConnect modal displaying a QR code to scan with a compatible wallet]*

Once logged in, the user can freely use the DApps with their wallet and sign transactions. **Infura** services are used to run **certain providers**.

### Deployment automation

To allow for **maximum responsiveness during the deployment** or development phases, many tasks are **automated**.

For the deployment of the smart contracts, scripted **deployment pipelines** were created to avoid paying high gas fees.

Numerous **unit** and **functional** tests cover all the project's features, and modules also make it possible to predict the amount of gas that will be consumed by the different methods. Security **audits** are also carried out using tools such as **Slither**.

*[image: Gas report listing the deployment cost of the Kazoku, KazokuGenesis, KazoShop, KazoStackV2, KazoToken and TheKazokus contracts, with 81 passing tests]*

For deploying the web applications, database, reverse proxy, and resolver, **Docker** and **Docker Compose** are of great help. They make it possible to quickly **launch**, **rebuild**, **modify**, and **stop** the entire application stack or just a part of it. This is very useful, for example, for quickly scaling server power down or up depending on the situation.

Cloudflare is also used as a **proxy** for the **production servers**. This enables caching, which reduces server load times, and brings more **security** to the project.

---

## Media

*[image: Home page of the Kazoku manager, "Welcome to Kazoku City", with a connected wallet and Kazoku No. 972 of the Omazi faction]*

*[image: Staking page of the manager listing Genesis Kazokus with their passive and active staking status, balance and claim actions]*

*[image: Kazoku marketplace offering two items, "Commander Pack" and "WhiteList phase 2", each with its price and a Buy button]*

*[image: Kazoku voting page showing four example proposals with their vote counts]*

*[image: Cloudflare overview over 24 hours: 8.59k unique visitors, 483.45k requests, 96.84% cached and 29 GB of data served]*

*[image: Kazoku artwork of a character seen in profile, lit by pink neon signs]*
