首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WAGMI useWaitForTransaction未运行

WAGMI useWaitForTransaction未运行
EN

Ethereum用户
提问于 2022-12-14 19:06:09
回答 1查看 503关注 0票数 1

我试图让useWaitForTransaction运行,以将应用程序的状态从提交更改为成功或失败,但它没有运行。这很奇怪,因为如果我硬将散列编码成'0x5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060',,而不是像'0x654b47a2b0b7dbea231548ee2527aff882f554dba2e66bea00765624a06ff5b8'.这样的契约交互的事务,它就会运行。

代码如下:

代码语言:javascript
复制
const { data, isError, isLoading } = useContractReads({
    contracts: [
      {
        ...lotteryContract,
        functionName: "getLotteryNumber",
      },
      {
        ...lotteryContract,
        functionName: "lottery_state",
      },
      {
        ...lotteryContract,
        functionName: "getPotAmount",
      },
      {
        ...lotteryContract,
        functionName: "winners",
        args: -1,
      },
    ],
    onSuccess(data) {
      console.log("Success", data);
      setLotteryNumber(data[0].toString());
      setStatus(lotteryStatusMap[data[1]]);
      setCurrentPotAmount(ethers.utils.formatEther(data[2].toString()));
      setAmountOfEntries(
        Math.ceil(ethers.utils.formatEther(data[2].toString()) * 100)
      );
      setLastWinnerAddress(data[3]);
      setLoadingContract(false);
    },
  });

  const { config } = usePrepareContractWrite({
    address: contractData.address,
    abi: contractData.abi,
    chainId: 5,
    functionName: "enter",
    overrides: {
      value: ethers.utils.parseEther(entryFee.toString()),
    },
  });

  const enterRaffle = useContractWrite({
    ...config,
    onSuccess(data) {
      setEnteringLottery(true);
      setTxHash(data.hash);
      setEnteringError(null);
      console.log(data);
    },
    onError(error) {
      setEnteringError(error.message);
    },
  });

  const waitForTransaction = useWaitForTransaction({
    hash: enterRaffle.data?.hash,
    onSuccess(data) {
      setEnteringLottery(false);
      setEnteredSuccess(true);
      setEnteringError(null);
      console.log("Success", data);
    },
    onError(error) {
      setEnteringLottery(false);
      setEnteredSuccess(false);
      setEnteringError(error.message);
    },
  });

任何帮助都是非常感谢的!

EN

回答 1

Ethereum用户

发布于 2022-12-16 14:07:37

代码语言:javascript
复制
    ...config,
    onSuccess(data) {
      setEnteringLottery(true);
      setTxHash(data.hash);
      setEnteringError(null);
      console.log(data);
    },
    onError(error) {
      setEnteringError(error.message);
    },
  });

  const waitForTransaction = useWaitForTransaction({
    hash: enterRaffle?.hash,
    onSuccess(data) {
      setEnteringLottery(false);
      setEnteredSuccess(true);
      setEnteringError(null);
      console.log("Success", data);
    },
    onError(error) {
      setEnteringLottery(false);
      setEnteredSuccess(false);
      setEnteringError(error.message);
    },
  });

您应该像这样调用send函数:write?.()write()

我认为waitForTransaction钩子混淆了--这是一个函数或sendTransaction的结果。

票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/141235

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档