Integrating web3 in cloud functions module

2019-07-25 02:10发布

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

Error: Invalid JSON RPC response: ""

Here is part of the implementation:

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

const db = admin.database();

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

const web3 = new Web3(provider);

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.

Thanks in advance.

1条回答
一夜七次
2楼-- · 2019-07-25 02:57

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.

Hope this helps someone.

查看更多
登录 后发表回答