truffle:创建合约实例时出错-地址0x3800e97896c6fdb614b9d011c9344dea32e490



我使用松露在以太坊节点上部署了一个简单的'HelloWorld'合约。我正在尝试访问和调用一个节点API内的合约函数。

代码如下:

var Web3 = require('web3');
var express = require('express');
const app = express();
app.use(express.json());
const artifact = require('./../ethereumapp/example/smartContract/build/contracts/HelloWorld.json')
const contract = require('truffle-contract');
const HelloWorldContract = contract(artifact);
var web3 = new Web3('http://localhost:8000');
HelloWorldContract.setProvider(web3.currentProvider);
var contractapp = HelloWorldContract.at('0x3800e97896c6fdb614b9d011c9344dea32e49047').catch((err)={
//Error gets thrown here
console.error("Error in creating instance of HelloWorld :"+err)}
);
app.get('/', (req, res)=>{
res.send("Hey! The app is up and running");
});
app.get('/getMessage',(req,res)=>{
console.log('Invoking smart contract...');
res.send(contractapp.getMessage());
});
app.listen(3000, ()=>{
console.log("App started on 3000");
});

我是以太坊/松露新手,无法找出抛出此错误的原因。请提供任何示例nodejs代码,可以帮助我整理这个

在我的例子中,这个错误的发生是因为合约部署事务耗尽了gas。Truffle用于部署的默认气体限制是6721975(参考:Truffle general options)。

下面是在部署演练中出现的帮助文本,解释了这个问题:

Error:  *** Deployment Failed ***
"LinearLiquidityPool" ran out of gas. Something in the constructor (ex: infinite loop) caused gas estimation to fail. Try:
* Making your contract constructor more efficient
* Setting the gas manually in your config or as a deployment parameter
* Using the solc optimizer settings in 'truffle-config.js'
* Setting a higher network block limit if you are on a
private network or test client (like ganache).

最新更新