【问题标题】:Then function not executing然后函数不执行
【发布时间】:2021-11-09 01:09:38
【问题描述】:

所以我一直试图在 contract.methods.registerVoter 函数通过后执行 mint 函数,但我没有运气。只有 contract.methods.registerVoter 函数被执行,而 then 函数中什么也没有发生。我做错了什么?

export async function registerVoter(walletAddress) {

   const contract = await getContract();

   const votingToken = await getTokenCotract();

   const tokenAddress = await getTokenAddress();

   const web3 = window.web3;

   contract.methods.registerVoter(walletAddress, tokenAddress).send({from: walletAddress}).then(() => {
       votingToken.methods.mint(walletAddress, 1).send({from: walletAddress})
})      

}

【问题讨论】:

    标签: callback ethereum web3js


    【解决方案1】:

    因为getContract中的send函数不是promise

    【讨论】:

    • getContract 只返回一个合约实例
    • function registerVoter(address _voter, address _token) external { require(registeredVoter[_voter] == false, "WKNDElection::You have already registered"); registeredVoter[_voter] = true; emit VoterRegistered(_voter); }
    • 我分别测试了te函数,它们都可以工作,所以任何函数本身都没有问题,只是程序永远不会进入then部分。
    • 这是因为没有一个函数返回一个承诺
    猜你喜欢
    • 1970-01-01
    • 2013-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多