diff --git a/smart-contracts-hardhat/bun.lockb b/smart-contracts-hardhat/bun.lockb index 7214fab..69c31c2 100755 Binary files a/smart-contracts-hardhat/bun.lockb and b/smart-contracts-hardhat/bun.lockb differ diff --git a/smart-contracts-hardhat/consts/LSP4SampleMetadata.ts b/smart-contracts-hardhat/consts/LSP4SampleMetadata.ts new file mode 100644 index 0000000..ac4f4e0 --- /dev/null +++ b/smart-contracts-hardhat/consts/LSP4SampleMetadata.ts @@ -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 + }, + }, +]; diff --git a/smart-contracts-hardhat/scripts/attachAssetMetadataEOA.ts b/smart-contracts-hardhat/scripts/attachAssetMetadataEOA.ts new file mode 100644 index 0000000..9208d8b --- /dev/null +++ b/smart-contracts-hardhat/scripts/attachAssetMetadataEOA.ts @@ -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); + }); diff --git a/smart-contracts-hardhat/scripts/deployEOA.ts b/smart-contracts-hardhat/scripts/deployEOA.ts index 6c5e7da..1fc7a6e 100644 --- a/smart-contracts-hardhat/scripts/deployEOA.ts +++ b/smart-contracts-hardhat/scripts/deployEOA.ts @@ -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 @@ -18,7 +18,7 @@ async function main() { console.log(`Token address: ${CustomTokenAddress}`); } -main() +deployToken() .then(() => process.exit(0)) .catch((error) => { console.error(error); diff --git a/smart-contracts-hardhat/scripts/deployUP.ts b/smart-contracts-hardhat/scripts/deployUP.ts index d35a1ca..819af00 100644 --- a/smart-contracts-hardhat/scripts/deployUP.ts +++ b/smart-contracts-hardhat/scripts/deployUP.ts @@ -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 @@ -71,7 +68,7 @@ async function main() { console.log('Custom token address: ', CustomTokenAddress); } -main() +deployToken() .then(() => process.exit(0)) .catch((error) => { console.error(error);