Deploy a Polyland ERC-721 metaverse contract on Harmony devnet using Foundry, minting finite land patches as NFTs through a Chainstack endpoint.
TLDR:
This tutorial showcases how to create an ERC-721 “Polyland” contract on Harmony devnet that treats each land patch as an NFT.
Polyland can hold a finite set of triangular patches, and the owner (contract deployer) can mint them to different accounts until the supply is capped.
Foundry is used to compile and deploy the contract, then the Harmony explorer is used to verify it and distribute patches.
Once deployed, each patch’s owner and properties (triangle edges) can be queried on-chain, illustrating the fundamentals of a metaverse asset contract.
The blockchain part of any metaverse that involves decentralization is object ownership.On Harmony, object ownership can be realized with the HRC-721 token standard, commonly known as NFT.A very basic example of realizing a metaverse on blockchain is creating a plot of land and distributing the patches of it to different owners—all through an NFT contract.In this tutorial, you will:
Create a simple contract called Polyland. The Polyland contract represents a plot of land.
Program Polyland to consist of patches of land.
Deploy Polyland on the Harmony devnet through a node deployed with Chainstack.
Distribute patches of Polyland to different accounts on the Harmony devnet.
The contract consists of a Triangle object with three edge properties. The triangle is a patch of land that has three edges.
The constructor function sets the contract up with four triangles. Since this is an array and starts with 0, while the ID of the minted patch starts with 1, the first element is set to Triangle0. Triangle0 is the default first element that will not represent a patch of land in the Polyland metaverse.
Through the maxSupply variable and the supplyCap modifier, the number of patches available to mint is capped at 4.
Only the address that deploys the contract can mint the patches of land.
Thus, the contract represents a plot of land called Polyland that consists of four triangular patches of land.
Set up OpenZeppelin with FoundryInstall OpenZeppelin with Foundry:
forge install openzeppelin/openzeppelin-contracts
In the project directory, create a remappings.txt file with the following contents:
@openzeppelin/=lib/openzeppelin-contracts/
Flatten the contract.Flatten the contract to make it easier to verify on the Harmony Testnet explorer.Run:
Polyland — the name of the contract as provided in the contract code contract Polyland is ERC721, Ownable
/root/polyland/src/polylandFlat.sol — full path to the flattened contract
YOUR_PRIVATE_KEY — the private key to the account that deploys the contract. Must be used without the 0x prefix. Fund the account with devnet ONE using the testnet faucet.
In mintTriangle, provide an address to distribute a patch of land to. Distribute the patches to different addresses until you hit the cap with the All patches minted message.
On the Read Contract tab, query the ownerOf field by putting in the tokenId values representing each of the patches of land: 1, 2, 3, 4.
In the triangles field, put in the same tokenId values to get the data on each of the patches: name and the size of each of the three edges.
This tutorial guided you through the basics of creating and deploying a metaverse contract with object ownership representation.You created your own plot of land, distributed the finite number of land patches to different owners, and retrieved the data for each of the patches: patch size and patch owner.You did all of it using Foundry.This tutorial uses devnet, however, the exact same instructions and sequence work on the mainnet.