Skip to content
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 4 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified smart-contracts-hardhat/bun.lockb
Binary file not shown.
68 changes: 68 additions & 0 deletions smart-contracts-hardhat/consts/LSP4SampleMetadata.ts
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
},
},
];
55 changes: 55 additions & 0 deletions smart-contracts-hardhat/scripts/attachAssetMetadataEOA.ts
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')
Copy link
Contributor

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?

Suggested change
attachAssetMetadata('0xdb86734b1e27F9A1e73627af6238171BD7d3716C')
const XXX_TESTNET_ADDRESS = '0xdb86734b1e27F9A1e73627af6238171BD7d3716C';
attachAssetMetadata(XXX_TESTNET_ADDRESS)

.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
4 changes: 2 additions & 2 deletions smart-contracts-hardhat/scripts/deployEOA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as dotenv from 'dotenv';

dotenv.config();

async function main() {
async function deployToken() {
const [deployer] = await ethers.getSigners();
const customToken = await ethers.deployContract('MyCustomToken', [
'My Custom Token', // token name
Expand All @@ -18,7 +18,7 @@ async function main() {
console.log(`Token address: ${CustomTokenAddress}`);
}

main()
deployToken()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
Expand Down
9 changes: 3 additions & 6 deletions smart-contracts-hardhat/scripts/deployUP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ import LSP0Artifact from '@lukso/lsp-smart-contracts/artifacts/LSP0ERC725Account
// load env vars
dotenv.config();

async function main() {
// Setup the provider
const provider = new ethers.JsonRpcProvider('https://rpc.testnet.lukso.gateway.fm');

async function deployToken() {
// Setup the controller used to sign the deployment
const signer = new ethers.Wallet(process.env.PRIVATE_KEY as string, provider);
const [signer] = await ethers.getSigners();
console.log('Deploying contracts with Universal Profile Controller: ', signer.address);

// Load the Universal Profile
Expand Down Expand Up @@ -71,7 +68,7 @@ async function main() {
console.log('Custom token address: ', CustomTokenAddress);
}

main()
deployToken()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
Expand Down