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

using the CreatorContract in a Next JS / Typescript project #462

Open
Booker-CU opened this issue Oct 25, 2024 · 11 comments
Open

using the CreatorContract in a Next JS / Typescript project #462

Booker-CU opened this issue Oct 25, 2024 · 11 comments

Comments

@Booker-CU
Copy link

Hello... I am having trouble implementing the creatorClient contract in NextJS w/ Typescript..

Here are my 2 function.
I am passing in an imagebuffer which is an AI generated image.
How do I use it inside the creatorClient.create1155 function?

Do I first need to do something w/ makeImageTokenMetadata, makeContractMetadata first to get the token and contract uri's? -- but then what do I do?

Also how would I call them correctly (makeImageTokenMetadata, makeContractMetadata)

thanks

import {
    useAccount,
    useWriteContract,
} from "wagmi";

import { creatorClient, publicClient } from "../config/zoraConfig";
import { makeImageTokenMetadata, makeContractMetadata } from "./zoraMetaDataUtil";

export async function createNFT(imageBuffer: string) {

    const { address } = useAccount();

    if (!publicClient || !address) {
        throw new Error("No public client or address found");
    }

    const { parameters, contractAddress} = await creatorClient.create1155({

        contract: {

            //Contract Name
            name: "My NFT Collection",

            //Contract Metadata URI
            uri: "ipfs://DUMMY/contract.json",
        },
        token: {
            tokenMetadataURI: "ipfs://TOKEN_URI",
        },
        account: address,
    });

    return { parameters, contractAddress };
}

export async function executeMint(parameters: any) {
    const { writeContract } = useWriteContract();
    const { abi } = parameters

    try {
      const txResult =  await writeContract(
        parameters.contractAddress,
        abi,
    );
      console.log(txResult)
      return txResult;
    } catch (error) {
      console.error('Error during NFT mint:', error);
      throw error;
    }
}
@iainnash
Copy link
Collaborator

We strongly recommend using an IPFS service to upload your image before posting and incorporate that url in the make contract and token metadata fields. There are a number of IPFS services that will handle standard NFT metadata and docs on the spec here: https://docs.zora.co/contracts/Metadata

Let us know if we can help clarify this information further :).

@Booker-CU
Copy link
Author

We strongly recommend using an IPFS service to upload your image before posting and incorporate that url in the make contract and token metadata fields. There are a number of IPFS services that will handle standard NFT metadata and docs on the spec here: https://docs.zora.co/contracts/Metadata

Let us know if we can help clarify this information further :).

thanks for the message... was curious, does the writeContract function return anything?

const txResult = await writeContract(
parameters.contractAddress,
abi,
);
it says its returning type VOID

Thanks

@Booker-CU
Copy link
Author

have another question... I am now using 'ipfs-http-client' to pin image to ipfs...

//Pin ImageBuffer to IPFS
const { cid } = await ipfs.add(imageBuffer);
console.log('Image pinned to IPFS with CID:', cid.toString());
what do I do with makeImageTokenMetadata & makeContractMetadata functions (zoralabs sdk)... do I need to pass them both the cid, since the image is pinned to ipfs do I need to change part of the makeImageTokenMetadata function?

thanks

@iainnash
Copy link
Collaborator

iainnash commented Oct 25, 2024 via email

@Booker-CU
Copy link
Author

I have another related question... when using the CreatorContract does the writeContract() function from wagmi return anything? here is my mint function code..

export async function executeMint(parameters: any) {
const { writeContract } = useWriteContract();
const { abi } = parameters

try {
  const txResult =  await writeContract(
    parameters.contractAddress,
    abi,
);
  console.log(txResult)
  return txResult;
} catch (error) {
  console.error('Error during NFT mint:', error);
  throw error;
}

}

using the creatorContract I get back my parameters and everything fine, and have a contract address and abi but when I call writeContract() function and pass in what it wants, when I console log txResults it says 'undefined'. I am trying to mint to zoraSepolia and also dont see anything there

@iainnash
Copy link
Collaborator

iainnash commented Nov 26, 2024 via email

@Booker-CU
Copy link
Author

yes it should return the hash of the transaction under the hash field.

On Tue, Nov 26, 2024 at 03:40 Booker @.> wrote: I have another related question... when using the CreatorContract does the writeContract() function from wagmi return anything? here is my mint function code.. export async function executeMint(parameters: any) { const { writeContract } = useWriteContract(); const { abi } = parameters try { const txResult = await writeContract( parameters.contractAddress, abi, ); console.log(txResult) return txResult; } catch (error) { console.error('Error during NFT mint:', error); throw error; } } using the creatorContract I get back my parameters and everything fine, and have a contract address and abi but when I call writeContract() function and pass in what it wants, when I console log txResults it says 'undefined'. I am trying to mint to zoraSepolia and also dont see anything there — Reply to this email directly, view it on GitHub <#462 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGMCOHPEQ72NDZ3QFWCKHD2CN4LRAVCNFSM6AAAAABQSKO6KOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIOJYHA4DENBWGY . You are receiving this because you commented.Message ID: @.>

should the entirety of 'parameters' be based through like 'writeContract(parameters)' or only the abi and contract address need to be passed in:
writeContract(
parameters.contractAddress,
parameters.abi,
);

@iainnash
Copy link
Collaborator

iainnash commented Dec 3, 2024

All parameters from simulate should be passed in.

@Booker-CU
Copy link
Author

All parameters from simulate should be passed in.

ok thanks, gonna try that one

@Booker-CU
Copy link
Author

I am having some problems creating a token on an existing contract... I have the parameters, plus a contract address... but an alert pops up and says it cant find the contract... the issue seems to happen at create1155OnExistingContract


  if (!address || !creatorClient) {
    alert("Please connect your wallet and ensure client is initialized");
    return;
  }

  setMintingOnZora(true);
  startMintingTransition(async () => {

    const contractAddress = parameters.contractAddress;


    try {
      if (!creatorClient || !creatorAccount) {
        throw new Error("creatorClient or creatorAccount is undefined");
      }
      const { parameters, prepareMint } = await creatorClient.create1155OnExistingContract({
        contractAddress,
        token: {
          tokenMetadataURI: contractAddress,
        },
        account: creatorAccount,
      });

      console.log(contractAddress)

      const { request } = await publicClient.simulateContract(parameters);

      // execute the transaction
      const hash = await walletClient.writeContract({
        ...request,
        account: address as `0x${string}`,
        chain: request.chain
      });
      // wait for the response
      const createReceipt = await publicClient.waitForTransactionReceipt({ hash });

      if (createReceipt.status !== "success") {
        throw new Error("create failed");
      }

      // pass the address as minterAccount
      const {mintParams} = prepareMint({
        quantityToMint: 1n,
        minterAccount: address,
      });

      if (!mintParams || !mintParams.parameters) {
        throw new Error("Invalid mint parameters");
      }

      // Rest of your minting logic...
      const mintHash = await walletClient.writeContract({
        ...mintParams,
        account: address as `0x${string}`,
        chain: mintParams.chain
      });

      const mintReceipt = await publicClient.waitForTransactionReceipt({
        hash: mintHash,
      });

      if (mintReceipt.status !== "success") {
        throw new Error("mint failed");
      }

    } catch (error) {
      console.error("Minting has failed", error);
      alert("Minting failed: " + (error as Error).message);
    } finally {
      setMintingOnZora(false);
    }
  });
};```

@Booker-CU
Copy link
Author

some additional info... I can create a deterministic contract and get a contractAddress. I can use that for the tokenAddress as well when I try to mint it? I keep getting contract not found. This is all on ZoraSepolia fyi

zora consolelogs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants