TypeError:getEntranceFee不是函数



我试图读取我的抽奖入场费,但我一直收到这个错误;

TypeError: getEnteranceFee is not a function

我知道getEnteranceFee中有一个拼写错误,但它不应该影响任何事情,因为到处都是这样。现在。

我试过这里给出的答案,但对我不起作用。

我不明白为什么useWeb3Contract无法获得函数。

RaffleEntrance.js组件

import { useWeb3Contract, useMoralis } from "react-moralis"
import { abi, contractAddresses } from "../constants"
import { useEffect } from "react"
// have a funtion to enter the lottery
export default function RaffleEntrance() {
const { chainId: chainIdHex, isWeb3Enabled } = useMoralis()
const chainId = parseInt(chainIdHex)
const raffleAddress = chainId in contractAddresses ? contractAddresses[chainId][0] : null
/* const{runContractFuction: enterRaffle} = useWeb3Contract({
abi: abi,
contractAddress: raffleAddress, // specify networkId
functionName: "enterRaffle",
params: {},
msgValue: 
}) */
const { runContractFuction: getEnteranceFee } = useWeb3Contract({
abi: abi,
contractAddress: raffleAddress, // specify networkId
functionName: "getEnteranceFee",
params: {},
})
useEffect(() => {
if (isWeb3Enabled) {
//try to read the raffle entrance fee
async function updateUI() {
const entranceFeeFromContract = await getEnteranceFee()
console.log(entranceFeeFromContract)
}
updateUI()
}
}, [isWeb3Enabled])
return <div>Hello from Lottery Entrance</div>
}

Raffle.sol片段

/* State Variables */
uint256 private i_enteranceFee;

/* Functions */
constructor(
address vrfCoordinatorV2, //address
uint256 enteranceFee,
bytes32 gasLane,
uint64 subscriptionId,
uint32 callbackGasLimit,
uint256 interval
) VRFConsumerBaseV2(vrfCoordinatorV2) {
i_vrfCoordinator = VRFCoordinatorV2Interface(vrfCoordinatorV2);
i_enteranceFee = enteranceFee;
i_gasLane = gasLane;
i_subscriptionId = subscriptionId;
i_callbackGasLimit = callbackGasLimit;
s_raffleState = RaffleState.OPEN;
s_lastTimeStamp = block.timestamp;
i_interval = interval;
}
/* view / pure functions */
function getEnteranceFee() public view returns (uint256) {
return i_enteranceFee;
}

ABI片段

{
"type": "function",
"name": "getEnteranceFee",
"constant": true,
"stateMutability": "view",
"payable": false,
"gas": 29000000,
"inputs": [],
"outputs": [{ "type": "uint256" }]
},

嗨,您在这一行中拼错了runContractFunction:

const { runContractFuction: getEnteranceFee } = useWeb3Contract({

应该是:

const { runContractFunction: getEnteranceFee } = useWeb3Contract({

我建议重命名getEnteranceFee,这样您就不会对代码中存在的打字错误进行规范化。

相关内容

  • 没有找到相关文章

最新更新