-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into update-metadata-up-guide
- Loading branch information
Showing
5 changed files
with
128 additions
and
8 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { EncodeDataInput } from '@erc725/erc725.js/build/main/src/types/decodeData'; | ||
|
||
export const LSP4SampleJSON = { | ||
LSP4Metadata: { | ||
name: 'CHILL', | ||
description: 'introducing $chill', | ||
links: [ | ||
{ | ||
title: 'X', | ||
url: 'https://twitter.com/chillwhales', | ||
}, | ||
{ | ||
title: 'Common Ground', | ||
url: 'https://app.cg/c/bZe26yK9Uh/', | ||
}, | ||
{ | ||
title: 'Chillwhales', | ||
url: 'https://chillwhales.com/', | ||
}, | ||
], | ||
icon: [ | ||
{ | ||
width: 1614, | ||
height: 1614, | ||
url: 'ipfs://bafkreigiidxipuk3y5ep5jygsfcs5pdqtfjhkges7hlpimt3mqksznoeyu', | ||
verification: { | ||
method: 'keccak256(bytes)', | ||
data: '0x583d661aed68417e9fd1500f629c8d9cd6fadd9c31e948b2a6870b66c4f3bc03', | ||
}, | ||
}, | ||
], | ||
images: [ | ||
[ | ||
{ | ||
width: 480, | ||
height: 480, | ||
url: 'ipfs://bafybeihejctjezrjiid3ed4aw5dq3vxlwqfvigdu77ucpszgtmitlza5ty', | ||
verification: { | ||
method: 'keccak256(bytes)', | ||
data: '0xd1ee7a4fe6d0a05f2929a8e47a68f1828d0145d113567a432391becf2ba83cbf', | ||
}, | ||
}, | ||
], | ||
], | ||
backgroundImage: [ | ||
{ | ||
width: 1200, | ||
height: 400, | ||
url: 'ipfs://bafybeiglmtsb7k7bhchfxphazb6lqln45uaox3lqvx557dk5he5wqxqp2i', | ||
verification: { | ||
method: 'keccak256(bytes)', | ||
data: '0xd22f654e7dee3971ff32220b8c91ddd3427842392087a9bcae8d218915859eee', | ||
}, | ||
}, | ||
], | ||
assets: [], | ||
}, | ||
}; | ||
|
||
export const lsp4SampleMetadata: EncodeDataInput[] = [ | ||
{ | ||
keyName: 'LSP4Metadata', | ||
value: { | ||
json: LSP4SampleJSON, | ||
url: 'ipfs://QmQTqheBLZFnQUxu5RDs8tA9JtkxfZqMBcmGd9sukXxwRm', // replace with example IPFS url | ||
}, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { ethers, network } from 'hardhat'; | ||
import * as dotenv from 'dotenv'; | ||
|
||
import { ERC725YDataKeys } from '@lukso/lsp-smart-contracts'; | ||
import LSP7DigitalAssetArtifact from '@lukso/lsp-smart-contracts/artifacts/LSP7DigitalAsset.json'; | ||
import LSP4DigitalAssetSchema from '@erc725/erc725.js/schemas/LSP4DigitalAsset.json'; | ||
import { ERC725 } from '@erc725/erc725.js'; | ||
import { lsp4SampleMetadata } from '../consts/LSP4SampleMetadata'; | ||
|
||
dotenv.config(); | ||
|
||
interface CustomNetworkConfig { | ||
url?: string; | ||
} | ||
|
||
async function attachAssetMetadata(myAssetAddress: string) { | ||
// Get the signer key | ||
const [signer] = await ethers.getSigners(); | ||
|
||
// Set up the token contract | ||
const token = new ethers.Contract(myAssetAddress, LSP7DigitalAssetArtifact.abi, signer); | ||
|
||
const metadataKey = ERC725YDataKeys.LSP4['LSP4Metadata']; | ||
|
||
const customNetworkConfig = network.config as CustomNetworkConfig; | ||
const networkUrl = customNetworkConfig.url; | ||
|
||
if (!networkUrl) { | ||
throw new Error('Network URL is not defined in the Hardhat configuration.'); | ||
} | ||
|
||
const erc725js = new ERC725(LSP4DigitalAssetSchema, myAssetAddress, networkUrl); | ||
|
||
// Read the current token metadata | ||
const currentMetadata = await erc725js.getData(metadataKey); | ||
console.log('Current token metadata:', currentMetadata); | ||
|
||
// Encode metadata | ||
const encodeLSP4Metadata = erc725js.encodeData(lsp4SampleMetadata); | ||
console.log('its encoding', encodeLSP4Metadata); | ||
|
||
// Update the token metadata | ||
const tx = await token.setDataBatch(encodeLSP4Metadata.keys, encodeLSP4Metadata.values); | ||
|
||
// Wait for the transaction to be included in a block | ||
const receipt = await tx.wait(); | ||
console.log('Token metadata updated:', receipt); | ||
} | ||
|
||
attachAssetMetadata('0xdb86734b1e27F9A1e73627af6238171BD7d3716C') | ||
.then(() => process.exit(0)) | ||
.catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters