-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update LSP4 Metadata for EOAs #33
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to put this address in a variable and to give it a name
Is it mainnet? testnet?