ourzora / zora-protocol

Monorepo for Zora Protocol (contracts & sdks)
MIT License
116 stars 72 forks source link

`getContractInfo` returns a different address #423

Closed alexcambose1 closed 2 weeks ago

alexcambose1 commented 3 months ago

Hey, I’m seeing an issue with the getContractInfo function from the SDK where the returned address is different than the one that actually the deployed contract has. For example the one in the screenshot is the generated one 0xEe94679F9857d32269ed890470b245b5Aa12a18 but actually it ends up as https://basescan.org/token/0xa289322757a36a0e1b61ee7f83e966e9b3057561 after deployment (or from the SetupNewContract event) image

oveddan commented 3 months ago

hey thanks for reporting this, can reproduce. looking into a fix.

neatonk commented 2 months ago

I have had similar issues. In my case I suspect it is due to the use of msg.sender in _hashContract. This value may change depending on how the transaction is submitted, e.g. when using a paymaster for sponsored transactions.

https://github.com/ourzora/zora-protocol/blob/5988cd0bc6e860d80cbbf74b60c8aa7f31c1b914/packages/1155-contracts/src/factory/ZoraCreator1155FactoryImpl.sol#L145-L159

iainnash commented 2 months ago

I we plan to deprecate this function due to this and other updates which make it harder to determine the final address.

oveddan commented 2 months ago

hey weve just pushed a fix for this. we still need to update the docs, but if you get @zoralabs/protocol-sdk@0.80 it will have this fix.

Couple things to note:

creatorClient.create1155 now only works for new contracts to add a token to an existing contract, use creatorClient.create1155OnExistingContract

create new 1155 and token:

import { createCreatorClient } from "@zoralabs/protocol-sdk";
import { publicClient, walletClient, chainId, creatorAccount } from "./config";

const creatorClient = createCreatorClient({ chainId, publicClient });

const { parameters, contractAddress } = await creatorClient.create1155({
  // by providing a contract creation config, the contract will be created
  // if it does not exist at a deterministic address
  contract: {
    // contract name
    name: "testContract",
    // contract metadata uri
    uri: "ipfs://DUMMY/contract.json",
  },
  token: {
    tokenMetadataURI: "ipfs://DUMMY/token.json",
  },
  // account to execute the transaction (the creator)
  account: creatorAccount,
  // how many tokens to mint to the creator upon token creation
});

// simulate the transaction
const { request } = await publicClient.simulateContract(parameters);

// execute the transaction
await walletClient.writeContract(request);

export { contractAddress };

create token on existing contract:


const { parameters } = await creatorClient.create1155OnExistingContract({
  // by providing a contract address, the token will be created on an existing contract
  // at that address
  contractAddress,
  token: {
    // token metadata uri
    tokenMetadataURI: "ipfs://DUMMY/token.json",
  },
  // account to execute the transaction (the creator)
  account: creatorAccount,
});

// simulate the transaction
const { request } = await publicClient.simulateContract(parameters);

// execute the transaction
const hash = await walletClient.writeContract(request);
// wait for the response
await publicClient.waitForTransactionReceipt({ hash });