将Web3集成到云功能模块中

将Web3集成到云功能模块中

本文介绍了将Web3集成到云功能模块中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将web3(使用松露)集成到云功能模块中,并且不断出现此错误:

I'm trying to integrate web3 (using truffle) in a cloud functions module and I keep getting this error:

Error: Invalid JSON RPC response: ""

这是实现的一部分:

admin.initializeApp(functions.config().firebase);

const db = admin.database();

const provider = new HDWalletProvider(mnemonic, infura link);

const web3 = new Web3(provider);

据我了解,该错误表明 truffle 库无法运行建立与以太坊网络的连接。我想知道这是否与将代码部署到Firebase有关。

As Far as I understand, the error indicates that truffle library is unable to establish a connection to the ethereum network. I wonder if this has something to do with deploying this code to firebase.

预先感谢。

推荐答案

我遇到了这个问题,我的问题是我的开发项目在Firebase的免费 Spark层上。 Cloud Functions中的传出网络请求要求您采用付费计划,因此我升级到了 Blaze层,即用即付,我的web3云功能立即开始工作。

I had this issue and my problem was that my dev project was on the free "Spark" tier for Firebase. Outgoing network requests in Cloud Functions requires that you are on a paid plan, so I upgraded to the "Blaze" tier which is pay as you go and my web3 cloud functions started working immediately.

希望这对某人有帮助。

这篇关于将Web3集成到云功能模块中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 14:05