ourzora / zora-protocol

Monorepo for Zora Protocol (contracts & sdks)
MIT License
113 stars 70 forks source link

viem@2.7.20: eth_signTypedData_v4: {"code":-32001,"message":"rpc method is not allowed"} #406

Closed maxmux-xyz closed 6 months ago

maxmux-xyz commented 6 months ago

Hi! Trying to call createPremint on createPremintClient, and getting the viem error below. I'm running simple ts-node env, with following dependencies:

"dependencies": {
    "@zoralabs/protocol-sdk": "^0.5.6",
    "viem": "^2.7.20"
  }

Full code here: https://github.com/maxmux-xyz/zora-sandbox See script.ts

Quick clarification questions: I want to pre-deploy/mint nft collection on behalf of a creator that is logged on my app through Privy & has an associated AA wallet. How should I call createPremint so that my logged in users AA wallet is the contract admin? Which account should be on the WalletClient, and which address should be the creatorAccount in the example here: https://github.com/maxmux-xyz/zora-sandbox/blob/4ee220f72a621724943262ac9f43576260b24744/script.ts#L66-L70 I also want to collect platform fees. Is that done through re-directs for our app for every different mint request?

/Users/maxime/dev/personal/zora-sdk/node_modules/viem/utils/rpc/http.ts:111
          throw new HttpRequestError({
                ^
HttpRequestError: HTTP request failed.

Status: 403
URL: https://mainnet.base.org
Request body: {"method":"eth_signTypedData_v4","params":["0x65318ba4d49C1da4B05F2632bB50e29637ed5A64","{\"domain\":{\"chainId\":8453,\"name\":\"Preminter\",\"version\":\"1\",\"verifyingContract\":\"0xe59c7040baf7d94c3ff740b1f7bf5ba74dbb75d4\"},\"message\":{\"deleted\":false,\"uid\":1,\"version\":0,\"tokenConfig\":{\"fixedPriceMinter\":\"0x04e2516a2c207e84a1839755675dfd8ef6302f0a\",\"maxSupply\":\"18446744073709551615\",\"maxTokensPerAddress\":\"0\",\"pricePerToken\":\"0\",\"mintDuration\":\"604800\",\"mintStart\":\"0\",\"royaltyMintSchedule\":0,\"royaltyBPS\":1000,\"royaltyRecipient\":\"0x65318ba4d49c1da4b05f2632bb50e29637ed5a64\",\"tokenURI\":\"ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u\"}},\"primaryType\":\"CreatorAttribution\",\"types\":{\"EIP712Domain\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"version\",\"type\":\"string\"},{\"name\":\"chainId\",\"type\":\"uint256\"},{\"name\":\"verifyingContract\",\"type\":\"address\"}],\"CreatorAttribution\":[{\"name\":\"tokenConfig\",\"type\":\"TokenCreationConfig\"},{\"name\":\"uid\",\"type\":\"uint32\"},{\"name\":\"version\",\"type\":\"uint32\"},{\"name\":\"deleted\",\"type\":\"bool\"}],\"TokenCreationConfig\":[{\"name\":\"tokenURI\",\"type\":\"string\"},{\"name\":\"maxSupply\",\"type\":\"uint256\"},{\"name\":\"maxTokensPerAddress\",\"type\":\"uint64\"},{\"name\":\"pricePerToken\",\"type\":\"uint96\"},{\"name\":\"mintStart\",\"type\":\"uint64\"},{\"name\":\"mintDuration\",\"type\":\"uint64\"},{\"name\":\"royaltyMintSchedule\",\"type\":\"uint32\"},{\"name\":\"royaltyBPS\",\"type\":\"uint32\"},{\"name\":\"royaltyRecipient\",\"type\":\"address\"},{\"name\":\"fixedPriceMinter\",\"type\":\"address\"}]}}"]}

Details: {"code":-32001,"message":"rpc method is not allowed"}
Version: viem@2.7.20
    at Object.request (/Users/maxime/dev/personal/zora-sdk/node_modules/viem/utils/rpc/http.ts:111:17)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async fn (/Users/maxime/dev/personal/zora-sdk/node_modules/viem/clients/transports/http.ts:113:19)
    at async request (/Users/maxime/dev/personal/zora-sdk/node_modules/viem/clients/transports/http.ts:118:39)
    at async delay.count.count (/Users/maxime/dev/personal/zora-sdk/node_modules/viem/utils/buildRequest.ts:104:18)
    at async attemptRetry (/Users/maxime/dev/personal/zora-sdk/node_modules/viem/utils/promise/withRetry.ts:39:22) {
  details: '{"code":-32001,"message":"rpc method is not allowed"}',
  docsPath: undefined,
  metaMessages: [
    'Status: 403',
    'URL: https://mainnet.base.org',
    'Request body: {"method":"eth_signTypedData_v4","params":["0x65318ba4d49C1da4B05F2632bB50e29637ed5A64","{\\"domain\\":{\\"chainId\\":8453,\\"name\\":\\"Preminter\\",\\"version\\":\\"1\\",\\"verifyingContract\\":\\"0xe59c7040baf7d94c3ff740b1f7bf5ba74dbb75d4\\"},\\"message\\":{\\"deleted\\":false,\\"uid\\":1,\\"version\\":0,\\"tokenConfig\\":{\\"fixedPriceMinter\\":\\"0x04e2516a2c207e84a1839755675dfd8ef6302f0a\\",\\"maxSupply\\":\\"18446744073709551615\\",\\"maxTokensPerAddress\\":\\"0\\",\\"pricePerToken\\":\\"0\\",\\"mintDuration\\":\\"604800\\",\\"mintStart\\":\\"0\\",\\"royaltyMintSchedule\\":0,\\"royaltyBPS\\":1000,\\"royaltyRecipient\\":\\"0x65318ba4d49c1da4b05f2632bb50e29637ed5a64\\",\\"tokenURI\\":\\"ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u\\"}},\\"primaryType\\":\\"CreatorAttribution\\",\\"types\\":{\\"EIP712Domain\\":[{\\"name\\":\\"name\\",\\"type\\":\\"string\\"},{\\"name\\":\\"version\\",\\"type\\":\\"string\\"},{\\"name\\":\\"chainId\\",\\"type\\":\\"uint256\\"},{\\"name\\":\\"verifyingContract\\",\\"type\\":\\"address\\"}],\\"CreatorAttribution\\":[{\\"name\\":\\"tokenConfig\\",\\"type\\":\\"TokenCreationConfig\\"},{\\"name\\":\\"uid\\",\\"type\\":\\"uint32\\"},{\\"name\\":\\"version\\",\\"type\\":\\"uint32\\"},{\\"name\\":\\"deleted\\",\\"type\\":\\"bool\\"}],\\"TokenCreationConfig\\":[{\\"name\\":\\"tokenURI\\",\\"type\\":\\"string\\"},{\\"name\\":\\"maxSupply\\",\\"type\\":\\"uint256\\"},{\\"name\\":\\"maxTokensPerAddress\\",\\"type\\":\\"uint64\\"},{\\"name\\":\\"pricePerToken\\",\\"type\\":\\"uint96\\"},{\\"name\\":\\"mintStart\\",\\"type\\":\\"uint64\\"},{\\"name\\":\\"mintDuration\\",\\"type\\":\\"uint64\\"},{\\"name\\":\\"royaltyMintSchedule\\",\\"type\\":\\"uint32\\"},{\\"name\\":\\"royaltyBPS\\",\\"type\\":\\"uint32\\"},{\\"name\\":\\"royaltyRecipient\\",\\"type\\":\\"address\\"},{\\"name\\":\\"fixedPriceMinter\\",\\"type\\":\\"address\\"}]}}"]}'
  ],
  shortMessage: 'HTTP request failed.',
  version: 'viem@2.7.20',
  body: {
    method: 'eth_signTypedData_v4',
    params: [
      '0x65318ba4d49C1da4B05F2632bB50e29637ed5A64',
      '{"domain":{"chainId":8453,"name":"Preminter","version":"1","verifyingContract":"0xe59c7040baf7d94c3ff740b1f7bf5ba74dbb75d4"},"message":{"deleted":false,"uid":1,"version":0,"tokenConfig":{"fixedPriceMinter":"0x04e2516a2c207e84a1839755675dfd8ef6302f0a","maxSupply":"18446744073709551615","maxTokensPerAddress":"0","pricePerToken":"0","mintDuration":"604800","mintStart":"0","royaltyMintSchedule":0,"royaltyBPS":1000,"royaltyRecipient":"0x65318ba4d49c1da4b05f2632bb50e29637ed5a64","tokenURI":"ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u"}},"primaryType":"CreatorAttribution","types":{"EIP712Domain":[{"name":"name","type":"string"},{"name":"version","type":"string"},{"name":"chainId","type":"uint256"},{"name":"verifyingContract","type":"address"}],"CreatorAttribution":[{"name":"tokenConfig","type":"TokenCreationConfig"},{"name":"uid","type":"uint32"},{"name":"version","type":"uint32"},{"name":"deleted","type":"bool"}],"TokenCreationConfig":[{"name":"tokenURI","type":"string"},{"name":"maxSupply","type":"uint256"},{"name":"maxTokensPerAddress","type":"uint64"},{"name":"pricePerToken","type":"uint96"},{"name":"mintStart","type":"uint64"},{"name":"mintDuration","type":"uint64"},{"name":"royaltyMintSchedule","type":"uint32"},{"name":"royaltyBPS","type":"uint32"},{"name":"royaltyRecipient","type":"address"},{"name":"fixedPriceMinter","type":"address"}]}}'
    ]
  },
  headers: Headers {
    [Symbol(headers list)]: HeadersList {
      [Symbol(headers map)]: [Map],
      [Symbol(headers map sorted)]: null
    },
    [Symbol(guard)]: 'immutable',
    [Symbol(realm)]: null
  },
  status: 403,
  url: 'https://mainnet.base.org'
}
iainnash commented 6 months ago

Hello!

To fix this with a local signer you need to pass in an Account to the createForFree function.

import {createPremintClient} from "@zoralabs/protocol-sdk";
import type {Address, PublicClient, WalletClient} from "viem";
import { createPublicClient, createWalletClient, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { base } from 'viem/chains'

async function createForFree({
  walletClient,
  publicClient,
  creator,
}: {
  // wallet client that will submit the transaction
  walletClient: WalletClient;
  // public client that will simulate the transaction
  publicClient: PublicClient;
  // address of the token contract
  creator: Account | Address;
}) {
  const premintClient = createPremintClient({chain: walletClient.chain!, publicClient: publicClient});

  // create and sign a free token creation.
  const createdPremint = await premintClient.createPremint({
    walletClient,
    // this line has been updated.
    creatorAccount: creator,
    checkSignature: true,
    collection: {
     // This line has been updated
      contractAdmin: if typeof creator === 'string' ? creator : creator.address,
      contractName: "Testing Contract",
      contractURI: "ipfs://bafkreiainxen4b4wz4ubylvbhons6rembxdet4a262nf2lziclqvv7au3e",
    },
    tokenCreationConfig: {
      tokenURI: "ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u",
    },
  });

  const premintUid = createdPremint.uid;
  const premintCollectionAddress = createdPremint.verifyingContract;

  return {
    // unique id of created premint, which can be used later to
    // update or delete the premint
    uid: premintUid,
    tokenContractAddress: premintCollectionAddress,
  };
}

async function main() {
  const cl = createPublicClient({
    chain: base,
    transport: http(),
  })
  const blockNumber = await cl.getBlockNumber()
  console.log('blockNumber', blockNumber)

  const account = privateKeyToAccount('<0xPK>')
  account.address
  const wc = createWalletClient({
    account,
    chain: base,
    transport: http()
  })

  const {uid, tokenContractAddress} = await createForFree({
    walletClient: wc,
    publicClient: cl as PublicClient,
    creatorAccount: "0x65318ba4d49C1da4B05F2632bB50e29637ed5A64",
  })

  console.log('uid', uid)
  console.log('tokenContractAddress', tokenContractAddress)
}

main();