SOLC内部的firebase功能会导致部署错误

发布于 2025-02-01 22:04:18 字数 2048 浏览 2 评论 0原文

我需要在firebase功能中编译智能合约。我使用的是solc “ solc”:“^0.8.13”,在我的package.json中。

负责创建联系人的firebase函数的代码为;

const functions = require("firebase-functions");
const admin = require('firebase-admin');
const solc = require('solc');
const fs = require("fs");
const Web3 = require('web3');

exports.createSC = functions.https.onCall((data, context) => {
    if (!context.auth) return { data: data, status: 'error', code: 401, message: 'Not signed in' }
    return new Promise((resolve, reject) => {
            admin.auth().getUser(data.owner)
                .then(userRecord => {

                    //below function compiles the contract and returns abi/binary code etc
                    let contract = instantiateContract('sources/SnaphashToken.sol');
                    //use web3 to actually deploy contract
                    let web3;
                    //...code emitted...
                    resolve(contractDeployResult)
                })
                .catch(error => {
                    console.error('Error fetching user data:', error)
                    reject({ status: 'error', code: 500, error })
                })
    });
})

当在本地部署函数模拟器上时,这非常有效,但是在Firebase Cloud上部署时,我会得到此例外。

i  functions: updating Node.js 16 function ethereum-createSC(us-central1)...
Function failed on loading user code. This is likely due to a bug in the user code. Error message: Error: please examine your function logs to see the error cause: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs. Additional troubleshooting documentation can be found at https://cloud.google.com/functions/docs/troubleshooting#logging. Please visit https://cloud.google.com/functions/docs/troubleshooting for in-depth troubleshooting documentation.

Functions deploy had errors with the following functions:
        ethereum-createSC(us-central1)

当我在我的功能中评论const solc = require('solc')时,它会毫无问题地部署。我真的需要能够根据用户输入进行修改后部署智能合约,并感谢您的帮助

I need to compile a smart contract inside a firebase function. I am using solc "solc": "^0.8.13", in my package.json.

Code of the firebase function responsible to create the contact is;

const functions = require("firebase-functions");
const admin = require('firebase-admin');
const solc = require('solc');
const fs = require("fs");
const Web3 = require('web3');

exports.createSC = functions.https.onCall((data, context) => {
    if (!context.auth) return { data: data, status: 'error', code: 401, message: 'Not signed in' }
    return new Promise((resolve, reject) => {
            admin.auth().getUser(data.owner)
                .then(userRecord => {

                    //below function compiles the contract and returns abi/binary code etc
                    let contract = instantiateContract('sources/SnaphashToken.sol');
                    //use web3 to actually deploy contract
                    let web3;
                    //...code emitted...
                    resolve(contractDeployResult)
                })
                .catch(error => {
                    console.error('Error fetching user data:', error)
                    reject({ status: 'error', code: 500, error })
                })
    });
})

this works perfectly well when deployed on functions simulator locally but when deployed on firebase cloud I get this exception;

i  functions: updating Node.js 16 function ethereum-createSC(us-central1)...
Function failed on loading user code. This is likely due to a bug in the user code. Error message: Error: please examine your function logs to see the error cause: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs. Additional troubleshooting documentation can be found at https://cloud.google.com/functions/docs/troubleshooting#logging. Please visit https://cloud.google.com/functions/docs/troubleshooting for in-depth troubleshooting documentation.

Functions deploy had errors with the following functions:
        ethereum-createSC(us-central1)

When I comment out const solc = require('solc') in my function, it deploys without problems. I really need to be able to deploy smart contracts after modifying based on user input and would appreciate a help on it

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猥琐帝 2025-02-08 22:04:18

我发现,由于错误:内存限制超过,主题函数正在引起部署错误。我能够看到,在检查了使用firebase函数的功能的详细日志之后:log

2022-05-27T17:09:27.384860094Z E ethereum-createNft: Function cannot be initialized. Error: memory limit exceeded.

为了解决此问题,我将功能的内存从默认256MB提高到1GBtimeoutseconds从60秒到120秒

exports.createNft = functions.runWith({memory:'1GB',timeoutSeconds:120}).https.onCall((data, context) => {
..code here..
});

,然后部署成功

I found out that the subject function was causing deployment error because of Error: memory limit exceeded. I was able to see that after I checked detailed logs of the functions with firebase functions:log

2022-05-27T17:09:27.384860094Z E ethereum-createNft: Function cannot be initialized. Error: memory limit exceeded.

In order to fix this issue, I increased memory for the function from default 256MB to 1GB and timeoutSeconds from default 60 seconds to 120 seconds

exports.createNft = functions.runWith({memory:'1GB',timeoutSeconds:120}).https.onCall((data, context) => {
..code here..
});

And then deployment was successful

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文