Skip to content

Commit

Permalink
added 4everland ipfs scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
bearni95 committed May 13, 2024
1 parent 3c60735 commit 3d34e67
Show file tree
Hide file tree
Showing 7 changed files with 342 additions and 155 deletions.
3 changes: 2 additions & 1 deletion packages/taikoon-ui/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
PUBLIC_WALLETCONNECT_PROJECT_ID=
PUBLIC_IPFS_GATEWAY=
PUBLIC_IPFS_GATEWAY=https://taikoons.4everland.link/ipfs/
PUBLIC_LAUNCH_DATE=2024-05-26T00:00:00
10 changes: 5 additions & 5 deletions packages/taikoon-ui/src/generated/abi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/**
* - [__View Contract on Holesky Etherscan__](https://holesky.etherscan.io/address/0x0874bD201a33bff5Ebd4f8200c6482A72457FeF0)
* - [__View Contract on Holesky Etherscan__](https://holesky.etherscan.io/address/0xfDbaA6d6c382A2555856bFaB315D5E6F3CDA1393)
* -
*/
export const taikoonTokenAbi = [
Expand Down Expand Up @@ -544,16 +544,16 @@ export const taikoonTokenAbi = [
] as const;

/**
* - [__View Contract on Holesky Etherscan__](https://holesky.etherscan.io/address/0x0874bD201a33bff5Ebd4f8200c6482A72457FeF0)
* - [__View Contract on Holesky Etherscan__](https://holesky.etherscan.io/address/0xfDbaA6d6c382A2555856bFaB315D5E6F3CDA1393)
* -
*/
export const taikoonTokenAddress = {
17000: '0x0874bD201a33bff5Ebd4f8200c6482A72457FeF0',
31337: '0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82',
17000: '0xfDbaA6d6c382A2555856bFaB315D5E6F3CDA1393',
31337: '0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512',
} as const;

/**
* - [__View Contract on Holesky Etherscan__](https://holesky.etherscan.io/address/0x0874bD201a33bff5Ebd4f8200c6482A72457FeF0)
* - [__View Contract on Holesky Etherscan__](https://holesky.etherscan.io/address/0xfDbaA6d6c382A2555856bFaB315D5E6F3CDA1393)
* -
*/
export const taikoonTokenConfig = {
Expand Down
5 changes: 4 additions & 1 deletion packages/taikoon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
"scripts": {
"clean": "rm -rf abis cache* && forge clean",
"compile": "forge build --build-info --extra-output storage-layout",
"eslint": "pnpm exec eslint --ignore-path .eslintignore --ext .js,.ts .",
"eslint": "pnpm exec eslint --ignore-path .eslintignore --ext .js,.ts . --fix",
"fmt:sol": "forge fmt",
"lint:sol": "forge fmt && pnpm solhint 'contracts/**/*.sol'",
"test": "pnpm clean && pnpm compile && forge test --match-path 'test/*.t.sol' -vvv",
"node": "anvil",
"merkle": "node script/js/generate-merkle-tree.js",
"deploy:localhost": "forge clean && pnpm compile && forge script script/sol/Deploy.s.sol --rpc-url http://localhost:8545 --broadcast",
"deploy:holesky": "forge clean && pnpm compile && forge script script/sol/Deploy.s.sol --rpc-url https://l1rpc.hekla.taiko.xyz/ --broadcast --gas-estimate-multiplier 200",
"publish:ipfs": "node script/js/4everland.js",
"deploy:ipfs": "rm -rf data/metadata/* && node script/js/resize-images.js && node script/js/add-images-ipfs.js && echo 'IPFS Base URI:' && ipfs add -r ./data/metadata/ && echo 'Update your .env file with the new IPFS URI'"
},
"devDependencies": {
Expand All @@ -33,6 +34,8 @@
"typescript": "^5.2.2"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.574.0",
"@aws-sdk/lib-storage": "^3.574.0",
"@openzeppelin/contracts": "5.0.2",
"@openzeppelin/contracts-upgradeable": "5.0.2",
"@openzeppelin/merkle-tree": "^1.0.6",
Expand Down
166 changes: 166 additions & 0 deletions packages/taikoon/script/js/4everland.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
const { S3 } = require("@aws-sdk/client-s3");
const { Upload } = require("@aws-sdk/lib-storage");
const fs = require("fs");
const fsPromises = fs.promises;
const path = require("path");

async function uploadFile(s3, params) {
try {
const task = new Upload({
client: s3,
queueSize: 3, // 3 MiB
params,
});

const res = await task.done();
return res.ETag.split('"').join("");
} catch (error) {
if (error) {
console.log("task", error.message);
}
}
}

// Helper function to form the metadata JSON object
function populateNFTMetadata(name, description, CID) {
return {
name,
description,
image: CID,
};
}

async function main() {
const s3Params = {
accessKey: "KYEKUCIU01RUW4LL5M26",
secretKey: "f+htmVYyj9IMN1XOoJfuVuYr08P6vb4ZW2xhxIQM",
};
const { accessKey, secretKey } = s3Params;
const s3 = new S3({
endpoint: "https://endpoint.4everland.co",
credentials: {
accessKeyId: accessKey,
secretAccessKey: secretKey,
},
region: "4EVERLAND",
});

// Get the images to upload from the local filesystem (/images)
console.log(`Importing images from the images/ directory...`);
const imgDirPath = path.join(path.resolve(__dirname, "../../data"), "images");
const filesName = await fsPromises.readdir(imgDirPath, (err) => {
if (err) {
console.log("Import from directory failed: ", err);
}
});

// Uploading images to IPFS
console.log(`Uploading image data to IPFS...`);
const imageCIDs = [];
const imagesSummary = [];
let imageCount = 1;
const imagesName = filesName.filter((fileName) => fileName.includes(".png"));
for await (const imageName of imagesName) {
const imageFilePath = path.join(
path.resolve(__dirname, "../../data"),
"images",
imageName,
);
const params = {
Bucket: "taikoons-testbucket",
Key: imageName,
ContentType: "image/png",
Body: fs.readFileSync(imageFilePath),
};

const imageCID = await uploadFile(s3, params);

imageCIDs.push(imageCID);
imagesSummary.push({ imageCID, imageCount });
console.log(`Image ${imageCount} added to IPFS with CID of ${imageCID}`);
imageCount++;
}
console.log(` `);

// Add the metadata to IPFS
console.log(`Adding metadata to IPFS...`);
let taikoonId = 0;
for await (const imageCID of imageCIDs) {
taikoonId++;

// write into a file
fs.writeFileSync(
path.join(
path.resolve(__dirname, "../../data"),
"metadata",
`${taikoonId}.json`,
),
JSON.stringify(
populateNFTMetadata(
`Taikoon ${taikoonId}`,
"A Taikoon",
imageCID.toString(),
),
),
);

console.log(
path.join(
path.resolve(__dirname, "../../data"),
"metadata",
`${taikoonId}.json`,
),
);
/*
metadataCIDs.push(metadataCID);
for (let i = 0; i < imagesSummary.length; i++) {
if (imagesSummary[i].imageCID == imageCID) {
imagesSummary[i].metadataCID = metadataCID;
}
} */
// console.log(`Metadata with image CID ${imageCID} added to IPFS with CID of ${metadataCID}`);
}
console.log(` `);
/*
fs.writeFileSync(
path.join(
path.resolve(__dirname, "../../data"),
"metadata",
"summary.json",
),
JSON.stringify({ imagesSummary }),
);
*/
/*
const putObjectOutput = await s3.putObject({
Bucket: "bucketname",
Key: "key",
Body: "data content",
});
// multipart upload
const params = {
Bucket,
Key: file.name,
Body: file,
ContentType: file.type,
};
try {
const task = new Upload({
client: s3,
queueSize: 3, // 3 MiB
params,
});
task.on("httpUploadProgress", (e) => {
const progress = ((e.loaded / e.total) * 100) | 0;
console.log(progress, e);
});
await task.done();
} catch (error) {
if (error) {
console.log("task", error.message);
}
} */
}

main();
Loading

0 comments on commit 3d34e67

Please sign in to comment.