SOLC内部的firebase功能会导致部署错误
我需要在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现,由于
错误:内存限制超过
,主题函数正在引起部署错误。我能够看到,在检查了使用firebase函数的功能的详细日志之后:log
为了解决此问题,我将功能的内存从默认
256MB
提高到1GB
和timeoutseconds
从60秒到120秒,然后部署成功
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 withfirebase functions:log
In order to fix this issue, I increased memory for the function from default
256MB
to1GB
andtimeoutSeconds
from default 60 seconds to 120 secondsAnd then deployment was successful