【问题标题】:WalletConnect error while integration in ReactJS - Uncaught (in promise) TypeError: this.send is not a function在 ReactJS 中集成时出现 WalletConnect 错误 - Uncaught (in promise) TypeError: this.send is not a function
【发布时间】:2021-02-04 10:43:18
【问题描述】:

我正在将 WalletConnect 集成到 React DApp 但得到 this.send 不是函数错误。

我已确定问题出在 WalletConnectProvider 上,但我已按照他们文档中提到的相同步骤进行操作。

请查看我的代码并告诉我如何解决此问题。谢谢。

import WalletConnectProvider from '@walletconnect/web3-provider';
import config from './config';
import Web3 from 'web3';

export const walletConnect = async (setAddr) => {
//  Create WalletConnect Provider
const provider = new WalletConnectProvider({
    infuraId: config.tokenContract.infuraKey, // Required
});

//  Enable session (triggers QR Code modal)
await provider.enable();

console.log('provider', provider);
if (provider.connected) {
    console.log('wallet connect address', provider.accounts[0]);
    setAddr(provider.accounts[0]);
}

//  Create Web3
const web3 = new Web3(provider);
console.log('web3', web3);

const _contract = new web3.eth.Contract(
   config.tokenContract.contractABI,
   config.tokenContract.contractAddress
);
const data = await _contract.methods.hatchNest().encodeABI();
const gasPrice = 20000000000;
const gasLimit = 90000;

const tx = {
   from: '0xFF12586A1eCf65b56d828712A8d4B48D1CEC8962',
   to: config.tokenContract.contractAddress,
   data: data,
   gasPrice: web3.utils.toHex(gasPrice),
   gasLimit: web3.utils.toHex(gasLimit),
};
 // Send Transaction
 const txHash = await web3.eth.sendTransaction(tx);
 console.log('sendTransaction', txHash);
};

【问题讨论】:

  • 遇到了同样的问题。用 ethers.js 替换了 web3js,它就可以工作了。

标签: reactjs ethereum web3 metamask


【解决方案1】:

这是 web3.js 1.3.x 中的一个已知错误

https://github.com/ethereum/web3.js/issues/3790

降级 web3.js 1.2.x.

【讨论】:

    猜你喜欢
    • 2017-04-13
    • 2020-03-17
    • 2020-01-06
    • 2021-03-10
    • 2021-09-30
    • 2020-12-22
    • 2019-06-15
    • 2017-07-20
    • 1970-01-01
    相关资源
    最近更新 更多