TLDR:
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:
To get from zero to a deployed metaverse contract and patches of land distributed on the Harmony devnet, do the following:
With Chainstack, create a .
With Chainstack, join the Harmony devnet.
With Chainstack, access your Harmony node credentials.
With OpenZeppelin, create an HRC-721 contract.
With Foundry, flatten, compile, and deploy the contract through your Harmony node.
Verify the contract on the Harmony explorer.
Using the Harmony explorer as a web app, distribute the patches of land to accounts.
See Create a project.
See View node access and credentials.
See Foundry.
Initialize your project with Foundry:
This will create the project directory polyland
an initialize it.
Go to the polyland/src/
directory. In the directory, create your metaverse contract: polyland.sol
.
The contract implementation is the following:
Triangle
object with three edge
properties. The triangle is a patch of land that has three edges.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.maxSupply
variable and the supplyCap
modifier, the number of patches available to mint is capped at 4
.Thus, the contract represents a plot of land called Polyland that consists of four triangular patches of land.
Set up OpenZeppelin with Foundry
Install OpenZeppelin with Foundry:
In the project directory, create a remappings.txt
file with the following contents:
Flatten the contract.
Flatten the contract to make it easier to verify on the Harmony Testnet explorer.
Run:
Deploy the contract:
where
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 contract0x
prefix. Fund the account with devnet ONE using the testnet faucet.--legacy
— the Foundry flag to work with the EVM-based networks that are not EIP-1559 activated.Once the contract deploys, note the solc
and the Deployed
to values in the output.
Open the Harmony Testnet explorer.
Put in the contract address. Click the Contract tab.
Click Verify and Publish.
In the Contract Name
field, put Polyland
.
Set Chain Type
to devnet
.
In Compiler
, provide the solc
version that the contract compiled with.
In Optimizer
, set Yes
, 200
. Contract bytecode optimization with 200 runs is the default Foundry setting.
Paste the entirety of the flattened contract in the contract field and hit Submit.
This will verify the contract. You can now use the explorer as a web app to interact with the contract.
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.ownerOf
field by putting in the tokenId
values representing each of the patches of land: 1
, 2
, 3
, 4
.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.
TLDR:
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:
To get from zero to a deployed metaverse contract and patches of land distributed on the Harmony devnet, do the following:
With Chainstack, create a .
With Chainstack, join the Harmony devnet.
With Chainstack, access your Harmony node credentials.
With OpenZeppelin, create an HRC-721 contract.
With Foundry, flatten, compile, and deploy the contract through your Harmony node.
Verify the contract on the Harmony explorer.
Using the Harmony explorer as a web app, distribute the patches of land to accounts.
See Create a project.
See View node access and credentials.
See Foundry.
Initialize your project with Foundry:
This will create the project directory polyland
an initialize it.
Go to the polyland/src/
directory. In the directory, create your metaverse contract: polyland.sol
.
The contract implementation is the following:
Triangle
object with three edge
properties. The triangle is a patch of land that has three edges.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.maxSupply
variable and the supplyCap
modifier, the number of patches available to mint is capped at 4
.Thus, the contract represents a plot of land called Polyland that consists of four triangular patches of land.
Set up OpenZeppelin with Foundry
Install OpenZeppelin with Foundry:
In the project directory, create a remappings.txt
file with the following contents:
Flatten the contract.
Flatten the contract to make it easier to verify on the Harmony Testnet explorer.
Run:
Deploy the contract:
where
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 contract0x
prefix. Fund the account with devnet ONE using the testnet faucet.--legacy
— the Foundry flag to work with the EVM-based networks that are not EIP-1559 activated.Once the contract deploys, note the solc
and the Deployed
to values in the output.
Open the Harmony Testnet explorer.
Put in the contract address. Click the Contract tab.
Click Verify and Publish.
In the Contract Name
field, put Polyland
.
Set Chain Type
to devnet
.
In Compiler
, provide the solc
version that the contract compiled with.
In Optimizer
, set Yes
, 200
. Contract bytecode optimization with 200 runs is the default Foundry setting.
Paste the entirety of the flattened contract in the contract field and hit Submit.
This will verify the contract. You can now use the explorer as a web app to interact with the contract.
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.ownerOf
field by putting in the tokenId
values representing each of the patches of land: 1
, 2
, 3
, 4
.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.