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

Creating 1155 Collection with Privy Provider #6

Open
mattleesounds opened this issue Jun 7, 2024 · 11 comments
Open

Creating 1155 Collection with Privy Provider #6

mattleesounds opened this issue Jun 7, 2024 · 11 comments

Comments

@mattleesounds
Copy link

Hello, I am trying to deploy a new 1155 collection from a Privy embedded wallet and am getting this error:

Error creating collection: [TypeError: publicClient.readContract is not a function (it is undefined)]

Based on that error and looking at the SDK code, it appears that the SDK for creating collections only works with Viem providers, which is the only one with the readContract function as far as I can tell. Is this the case, and if so, is it still possible to create collections from a Privy Provider? FYI, Privy Provider follows the EIP 1193 standard.

@oveddan
Copy link
Collaborator

oveddan commented Jun 7, 2024

hey @mattleesounds could you provide a more full code example?

@mattleesounds
Copy link
Author

mattleesounds commented Jun 7, 2024

Sure, here ya go

import React, { useState } from "react"
import { Pressable, Text } from "react-native"
import { useEmbeddedWallet, isConnected } from "@privy-io/expo"
import { create1155CreatorClient } from "@zoralabs/protocol-sdk"

const CreateCollection: React.FC = () => {
  const wallet = useEmbeddedWallet()
  const [isCreated, setIsCreated] = useState(false)

  const createCollection = async (provider: EIP1193Provider) => {
    try {
      const accounts = await provider.request({
        method: "eth_requestAccounts",
      })
      const creatorClient = create1155CreatorClient({ publicClient: provider })
      const { request } = await creatorClient.createNew1155Token({
        contract: {
          name: "test-collection-1",
          uri: "https://gold-extraordinary-pigeon-404.mypinata.cloud/ipfs/QmbVrAKuxiHDVEdzhkQcC5euxYm3sLuf4M25FmavQgDpzm",
        },
        tokenMetadataURI:
          "https://gold-extraordinary-pigeon-404.mypinata.cloud/ipfs/QmXxJHtGti9r2jLpKkRDmQqnMkmb6DHUnUZd9RuvxPnHe5",
        account: accounts[0],
        mintToCreatorCount: 1,
      })
      const { request: simulateRequest } = provider.simulateContract(request)
      const hash = await provider.send({
        method: "eth_sendTransaction",
        params: [simulateRequest],
      })
      const receipt = await provider.request({
        method: "eth_getTransactionReceipt",
        params: [hash],
      })
      setIsCreated(true)
      console.log("Collection created:", receipt)
    } catch (error) {
      setIsCreated(false)
      console.error("Error creating collection:", error)
    }
  }

  return (
    <>
      <Pressable
        className="pt-4 "
        onPress={() => isConnected(wallet) && createCollection(wallet.provider)}
      >
        <Text className="text-white border-2  border-white text-center text-xl font-bold">
          CREATE COLLECTION
        </Text>
      </Pressable>
      {isCreated && (
        <Text className="text-green-500">Collection successfully created!</Text>
      )}
    </>
  )
}

export default CreateCollection

@oveddan
Copy link
Collaborator

oveddan commented Jun 7, 2024

hey so i tried to repro this locally, it looks like EIP1193Provider doesn't have a method readContract:

Screenshot 2024-06-07 at 12 16 48 PM

so it wouldn't work as an argument for publicClient for now.

we could add a better example and support for integration with privy. for now I found in their docs examples of creating a publicClient for using with other libs:

https://docs.privy.io/guide/react/recipes/account-abstraction/pimlico#_4-create-a-smart-account-for-your-user
https://docs.privy.io/guide/react/recipes/account-abstraction/wagmi#_1-initialize-an-eip1193-provider-for-the-smart-account

Perhaps until we better support privy you could manually setup a PublicClient like those example?

@mattleesounds
Copy link
Author

Will attempt! Thanks for the privy resources.

@Nith567
Copy link

Nith567 commented Jun 9, 2024

@oveddan Hey i am trying to mint nft's i saw the abi : "inputs": [
{
"internalType": "contract IMinter1155",
"name": "minter",
"type": "address"
},
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "quantity",
"type": "uint256"
},
{
"internalType": "address[]",
"name": "rewardsRecipients",
"type": "address[]"
},
{
"internalType": "bytes",
"name": "minterArguments",
"type": "bytes"
}
], here what are the minterArguments contains encodedbytes ? i saw in a sdk that it has : const mintArguments = {
quantityToMint: 1,
mintComment: "Summer Chain!",
mintReferral: "0x8879318091671ba1274e751f8cdef76bb37eb3ed"
};
but in args we already have quantitytomint so can you confirm it, while minting facing few errros thats why

@Nith567
Copy link

Nith567 commented Jun 9, 2024

@oveddan check this out: https://github.com/Nith567/mint-/blob/main/src/components/Transact.tsx
when i try to mint it, says: (execution reverted with data Try again)

@mattleesounds
Copy link
Author

mattleesounds commented Jun 10, 2024

@oveddan FYI, this turned out to be the relevant docs for integration with privy-expo SDK https://docs.privy.io/guide/expo/embedded/3p-libraries

@iainnash
Copy link

Hi!

We have different minter modules that take different arguments. Our SDK takes those arguments and encodes them for the fixed price minter module (our default).

It looks like the reason the last few transactions failed is that you attempted to call an NFT contract that has no NFTs/Mints registered:
Screenshot 2024-06-10 at 11 50 53 AM

@iainnash
Copy link

Can you try with an NFT that has a token created/registered on it with a sales strategy?

@oveddan
Copy link
Collaborator

oveddan commented Jun 10, 2024

@oveddan FYI, this turned out to be the relevant docs for integration with privy-expo SDK https://docs.privy.io/guide/expo/embedded/3p-libraries

great link @mattleesounds thank you! we can work on adding a section on privy integration to the docs, or look at ways to have more native integration

@Nith567
Copy link

Nith567 commented Jun 11, 2024

@iainnash yeah it did solved after i put correct parameters, tried through abi using wagmi hooks it worked out instead of sdk.

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

4 participants