forked from andrejrakic/rwa-primer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunctions-source-getNftMetadata.js
34 lines (28 loc) · 1.29 KB
/
Functions-source-getNftMetadata.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Import the ethers library from npm
const { ethers } = await import("npm:[email protected]");
const Hash = await import("npm:[email protected]");
// Make an HTTP request to fetch real estate data
const apiResponse = await Functions.makeHttpRequest({
url: `https://api.bridgedataoutput.com/api/v2/OData/test/Property('P_5dba1fb94aa4055b9f29696f')?access_token=6baca547742c6f96a6ff71b138424f21`,
});
// Extract relevant data from the API response
const realEstateAddress = apiResponse.data.UnparsedAddress;
const yearBuilt = Number(apiResponse.data.YearBuilt);
const lotSizeSquareFeet = Number(apiResponse.data.LotSizeSquareFeet);
const livingArea = Number(apiResponse.data.LivingArea);
const bedroomsTotal = Number(apiResponse.data.BedroomsTotal);
const metadata = {
name: "Real Estate Token",
attributes: [
{ trait_type: "realEstateAddress", value: realEstateAddress },
{ trait_type: "yearBuilt", value: yearBuilt },
{ trait_type: "lotSizeSquareFeet", value: lotSizeSquareFeet },
{ trait_type: "livingArea", value: livingArea },
{ trait_type: "bedroomsTotal", value: bedroomsTotal }
]
};
// Stringify the JSON object
const metadataString = JSON.stringify(metadata);
const ipfsCid = await Hash.of(metadataString);
console.log(ipfsCid);
return Functions.encodeString(`ipfs://${ipfsCid}`);