Managing Real Estate as Dynamic NFTs
Anil Dukkipatty
Posted on February 8, 2023
A hot topic of discussion amongst our community has been real estate tokenisation and how upgrades, issues and sales data regarding a property can be stored and shared easily using the blockchain. In light of this, we thought of creating a simple technical example to help you understand how you can tokenise your property as a dynamic NFT (dNFT) and store updates about it on the blockchain using Revise.
Introduction to Revise
Revise is a platform that’ll let you build dynamic NFTs. NFTs today are fairly static. Once you buy it they don’t change. What you see is what you get. Dynamic NFTs are able to react to the outside world, to data, to user interactions, etc. They are capable of changing, and evolving over time.
Let’s use Revise to build your own real estate NFT collection, then tokenise a real estate property and finally store changes that are occurring on this property. We won’t cover how to deploy these NFTs to Ethereum/Opensea (click here to learn more).
Create a Repo
Let’s clone this GitHub repo to get started. The repo is an empty Javascript project with revise-sdk added to the package manager. Once you cd
into the project folder, you can run npm install
to install all the dependencies. Let’s create an index.js
file. We’ll write all our code in this file, we’ll use node index.js
to run the program.
Copy and paste the following code into the index.js
file.
const { Revise } = require("revise-sdk");
const AUTH_TOKEN = "...PASTE YOUR AUTH TOKEN HERE...";
const revise = new Revise({auth: AUTH_TOKEN});
async function run() {
// write your code here
}
run()
In the first couple of lines, we’re importing the Revise-sdk and adding our auth token (more on how to get this below). In the third line, we’re instantiating the revise
object. We can now use this object to call all the functions needed to complete the exercise. Revise functions are mostly async, so we create a run
function which is async and can call the revise functions using the await
keyword. This will make our code more readable and maintainable.
💡 You can generate the Auth token from app.revise.network. For more details refer to the next section of this article.
Generate API Key (Auth Token)
Before we continue writing the rest of the code let’s go grab an auth key. Visit Revise and click on “get started”. Once you make an account and log in you’ll see the “generate API key” link in the header. Click on it, you should now be able to generate the API key (auth token). Copy the key that is shown on the screen and keep it safe. This key is not stored on Revise’s servers for security reasons. If you misplace the key it’s permanently lost. You can always come back and generate a new key.
Let’s replace the AUTH_TOKEN
in the above code with the key we just generated. Now we’re ready to start writing out Dynamic real estate NFT.
Add a Collection
To start with let’s make a collection called “My Properties”. This collection can have multiple NFTs. Each NFT is a property. In order to make the collection, we’ll call the addCollection
function. We’ll have to pass it two parameters, the name for the collection and the URI for the collection. The collectionURI
is a unique project name that can be used to generate links for the NFT (why we need these links is described later). We have to make sure that the URI is unique and a single word. For e.g. “myproperties" is a valid Collection URI “my properties are epic” is not. Add the following code to your index.js
inside the run
function.
const collection = await revise.addCollection({name: "My Properties", uri: "..CREATE YOUR UNIQUE URI"})
// Collection Name : Use any name you want for your collection (this gets shown in the marketplace))
// Collection_URI : Use a unique name (no spaces or special characters)
// this will generate a unique link for your collection
// for e.g. if you choose "myproperties12345"
// your baseURI wil be "myproperties.revise.link"
Add an NFT
Now let’s add our first NFT real estate. We’ll use the addNFT
function to create our real estate NFT. Add the following code to your run
function below the addCollection
function call.
const nft = await revise.addNFT({
image: 'https://revise-testing.fra1.cdn.digitaloceanspaces.com/tutorial/2023.png',
name: 'Castle Street Property',
tokenId: '1',
description: 'Townhouse with great interiors'
}, [
{street: "10 Castle Street"}, {maintenance_history: ""}, {age: "1"}, {past_sales: ""}
], collection.id)
console.log(nft)
We’re passing parameters for the image of our property, the name, description, tokenId
and some metadata properties. We’re also passing the collectionId
we received after creating our collection for the earlier code snippet. tokenId
is the unique ID of your NFT on the blockchain. This helps the blockchain and marketplaces distinguish between the NFTs part of the same collection. Two NFTs shouldn’t have the same tokenId
. We can add any amount of custom data to our NFTs via its attributes. As you can see in the above snippet we’ve added “street”, “maintenance_history“, age”, “past_sales” etc. You can add any number of attributes here.
Run
The final state of our index.js
file should look like this now.
const { Revise } = require("revise-sdk");
const AUTH_TOKEN = "...PASTE YOUR AUTH TOKEN HERE...";
const revise = new Revise({auth: AUTH_TOKEN});
async function run() {
const collection = await revise.addCollection({name: "My Properties", uri: "..CREATE YOUR UNIQUE URI"})
const nft = await revise.addNFT({
image: 'https://revise-testing.fra1.cdn.digitaloceanspaces.com/tutorial/2023.png',
name: 'Castle Street Property',
tokenId: '1',
description: 'Townhouse with great interiors'
}, [
{street: "10 Castle Street"}, {maintenance_history: ""}, {age: "1"}, {past_sales: ""}
], collection.id)
console.log(nft)
}
run()
Let’s run this file to create a collection and add our first NFT. Run node index.js
in your terminal. The expected output is an id
as shown below.
The command you ran earlier should output the id for the NFT we just created. The ID is the unique identifier for this NFT, we’ll be using this nftId
to fetch and makes updates to our real estate. Let’s store this ID carefully.
💡 Note: the tokenId
and nftId
are different. tokenId
is used by marketplaces and wallets to identify your NFT. nftId
is used by Revise to identify and control the NFT.
Visit your Revise dashboard to see your NFT real estate in action.
Click on the “View” button to see your NFT and it show show up with the image of your house from 2023.
Adding dynamic capabilities to your NFT
Now that we’ve created our NFT Real Estate property, let’s show any updates that have happened to it. Let’s add some mock data to show the maintenance related updates and also any new sales data for this house.
Create a new file called updates.js
. Paste the following code in the file.
const { Revise } = require("revise-sdk");
const AUTH_TOKEN = "...AUTH_TOKEN...";
const revise = new Revise({auth: AUTH_TOKEN});
const API = async function() {
const data ={maintenance_history : ["2022, New roof","2024, New deck"], past_sales : ["2022, $300,000", "2024, $380,000", "2028, $420,000"],image : "https://revise-testing.fra1.cdn.digitaloceanspaces.com/tutorial/2052.png"};
return data;
}
async function run() {
revise.every('10m').listenTo(API).start(async (data) => {
const property = await revise.fetchNFT("b73897be-cf0e-4517-8de7-cd83be8aae8d")
revise.nft(property)
.setProperty("maintenance_history", data.maintenance_history)
.setProperty("past_sales", data.past_sales)
.setImage(data.image)
.save()
console.log(`${property.name} is updated`)
})
}
run()
In the above code we are creating some mock data for maintenance_history and past_sales. Then we’re setting up automation which will fetch the data and update our real estate attributes every 10 minutes with a new image. Execute the above file by running node updates.js
. The program will execute automatically and show all the updates that have occurred to your real estate. We are aware that our UI does not display the information correctly (no spacing etc) - don’t worry this is getting fixed in our next release (coming soon!) 😊
Congrats on creating your real estate collection and property NFT! Publish your Real Estate NFT to Opensea and show it off to the world.
If you want to learn more or explore opportunities creating with Revise, please schedule a call with us here or join our Discord or message us on Twitter.
Posted on February 8, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.