Skip to content

Commit

Permalink
Now deploying mock nfts to show on marketplace
Browse files Browse the repository at this point in the history
  • Loading branch information
luloxi committed Sep 20, 2024
1 parent 6a88189 commit 750599d
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 12 deletions.
59 changes: 54 additions & 5 deletions packages/foundry/script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ contract DeployScript is ScaffoldETHDeploy {
address usdcOnAvalancheFuji = 0x5425890298aed601595a70AB815c96711a31Bc65;
address usdcOnPolygonAmoy = 0x41E94Eb019C0762f9Bfcf9Fb1E58725BfB0e7582;

SimpleMint simpleMint;
MockNFT mockNFT;
Marketplace marketplace;

error InvalidPrivateKey(string);

function run() external {
Expand All @@ -26,27 +30,27 @@ contract DeployScript is ScaffoldETHDeploy {
}
vm.startBroadcast(deployerPrivateKey);

SimpleMint simpleMint = new SimpleMint();
simpleMint = new SimpleMint();
console.logString(
string.concat(
"SimpleMint deployed at: ", vm.toString(address(simpleMint))
)
);

MockNFT mockNFT = new MockNFT();
mockNFT = new MockNFT();
console.logString(
string.concat("MockNFT deployed at: ", vm.toString(address(mockNFT)))
);

if (block.chainid == AVALANCHE_FUJI_CHAIN_ID) {
Marketplace marketplace = new Marketplace(usdcOnAvalancheFuji);
marketplace = new Marketplace(usdcOnAvalancheFuji);
console.logString(
string.concat(
"Marketplace deployed at: ", vm.toString(address(marketplace))
)
);
} else if (block.chainid == POLYGON_AMOY_CHAIN_ID) {
Marketplace marketplace = new Marketplace(usdcOnPolygonAmoy);
marketplace = new Marketplace(usdcOnPolygonAmoy);
console.logString(
string.concat(
"Marketplace deployed at: ", vm.toString(address(marketplace))
Expand All @@ -59,12 +63,14 @@ contract DeployScript is ScaffoldETHDeploy {
"Local USDC (MockUSDC) deployed at: ", vm.toString(address(localUSDC))
)
);
Marketplace marketplace = new Marketplace(address(localUSDC));
marketplace = new Marketplace(address(localUSDC));
console.logString(
string.concat(
"Marketplace deployed at: ", vm.toString(address(marketplace))
)
);
// Populate the marketplace with some initial NFTs
mintInitialMarketplaceNFTs();
}

vm.stopBroadcast();
Expand All @@ -77,5 +83,48 @@ contract DeployScript is ScaffoldETHDeploy {
exportDeployments();
}

function mintInitialMarketplaceNFTs() internal {
mockNFT.mintItem(
"https://ipfs.io/ipfs/Qmeh4aKV1DVBm324MFnKzUgmz74ZYFJPj77bZzsGoLjBaj"
);
mockNFT.approve(address(marketplace), 1);
mockNFT.mintItem(
"https://ipfs.io/ipfs/QmWgTmATX7weXVyimHkjaY7MJJro8ZM2mU6n4KrGt1yQgE"
);
mockNFT.approve(address(marketplace), 2);
mockNFT.mintItem(
"https://ipfs.io/ipfs/QmTy34vycaA6by2D5VadtqTazhg9pKa5ZAwpnnX7ust4qs"
);
mockNFT.approve(address(marketplace), 3);
mockNFT.mintItem(
"https://ipfs.io/ipfs/QmVxLz4mmP9uY4P3fbi88mpemWcAvnZYX8sbqKGk88x5YP"
);
mockNFT.approve(address(marketplace), 4);
simpleMint.startCollection(
"Vaquita en el Monte",
"VM",
"https://ipfs.io/ipfs/QmWRssgjvrkyoSwWspzxrHfU6DTMbdVY2oR6zKgzvtnts2",
msg.sender,
3 * 1e6,
30
);

// mockNFT.mintItem(
// "https://ipfs.io/ipfs/QmWRssgjvrkyoSwWspzxrHfU6DTMbdVY2oR6zKgzvtnts2"
// );
marketplace.createListing(
address(mockNFT), 1, 15 * 1e6, Marketplace.Currency.USDCToken, false, 0
);
marketplace.createListing(
address(mockNFT), 2, 15 * 1e16, Marketplace.Currency.NativeToken, false, 0
);
marketplace.createListing(
address(mockNFT), 3, 5 * 1e6, Marketplace.Currency.USDCToken, false, 0
);
marketplace.createListing(
address(mockNFT), 4, 5 * 1e16, Marketplace.Currency.NativeToken, false, 0
);
}

function test() public { }
}
8 changes: 4 additions & 4 deletions packages/nextjs/contracts/deployedContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { GenericContractsDeclaration } from "~~/utils/scaffold-eth/contract";
const deployedContracts = {
31337: {
SimpleMint: {
address: "0x5fbdb2315678afecb367f032d93f642f64180aa3",
address: "0xca8c8688914e0f7096c920146cd0ad85cd7ae8b9",
abi: [
{
type: "constructor",
Expand Down Expand Up @@ -320,7 +320,7 @@ const deployedContracts = {
},
},
MockNFT: {
address: "0xe7f1725e7734ce288f8367e1bb143e90bb3f0512",
address: "0xb0f05d25e41fbc2b52013099ed9616f1206ae21b",
abi: [
{
type: "constructor",
Expand Down Expand Up @@ -940,7 +940,7 @@ const deployedContracts = {
},
},
MockUSDC: {
address: "0x9fe46736679d2d9a65f0992f2272de9f3c7fa6e0",
address: "0x5feaebfb4439f3516c74939a9d04e95afe82c4ae",
abi: [
{
type: "constructor",
Expand Down Expand Up @@ -1397,7 +1397,7 @@ const deployedContracts = {
},
},
Marketplace: {
address: "0xcf7ed3acca5a467e9e704c703e8d87f634fb0fc9",
address: "0x976fcd02f7c4773dd89c309fbf55d5923b4c98a1",
abi: [
{
type: "constructor",
Expand Down
30 changes: 27 additions & 3 deletions packages/nextjs/utils/simpleNFT/ipfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,41 @@ import { create } from "kubo-rpc-client";

const PROJECT_ID = "2GajDLTC6y04qsYsoDRq9nGmWwK";
const PROJECT_SECRET = "48c62c6b3f82d2ecfa2cbe4c90f97037";
const PROJECT_ID_SECRECT = `${PROJECT_ID}:${PROJECT_SECRET}`;
const PROJECT_ID_SECRET = `${PROJECT_ID}:${PROJECT_SECRET}`;

export const ipfsClient = create({
host: "ipfs.infura.io",
port: 5001,
protocol: "https",
headers: {
Authorization: `Basic ${Buffer.from(PROJECT_ID_SECRECT).toString("base64")}`,
Authorization: `Basic ${Buffer.from(PROJECT_ID_SECRET).toString("base64")}`,
},
});

export async function getNFTMetadataFromIPFS(ipfsHash: string) {
/**
* Helper function to extract the IPFS hash from a full URL if necessary
*/
function extractIpfsHash(input: string): string {
// Check if the input is a full URL (e.g., https://ipfs.io/ipfs/Qm...)
if (input.startsWith("http")) {
// Extract the hash part after '/ipfs/'
const hashIndex = input.indexOf("/ipfs/");
if (hashIndex !== -1) {
return input.slice(hashIndex + 6); // Return everything after "/ipfs/"
}
}
// If it's already a hash, return it as is
return input;
}

/**
* Fetch NFT metadata from IPFS, handling both full URLs and raw IPFS hashes.
*/
export async function getNFTMetadataFromIPFS(ipfsInput: string) {
// Extract the IPFS hash from the input (either full URL or hash)
const ipfsHash = extractIpfsHash(ipfsInput);

// Fetch the metadata from IPFS
for await (const file of ipfsClient.get(ipfsHash)) {
// The file is of type unit8array so we need to convert it to string
const content = new TextDecoder().decode(file);
Expand All @@ -25,6 +48,7 @@ export async function getNFTMetadataFromIPFS(ipfsHash: string) {
// Extract the JSON object string
const jsonObjectString = trimmedContent.slice(startIndex, endIndex);
try {
// Parse the extracted JSON string
const jsonObject = JSON.parse(jsonObjectString);
return jsonObject;
} catch (error) {
Expand Down

0 comments on commit 750599d

Please sign in to comment.