【问题标题】:truffle: Error while creating instance of the contract - no code at address 0x3800e97896c6fdb614b9d011c9344dea32e49047松露:创建合约实例时出错 - 地址 0x3800e97896c6fdb614b9d011c9344dea32e49047 没有代码
【发布时间】:2021-02-24 07:01:38
【问题描述】:

我已经使用 truffle 在以太坊节点上部署了一个简单的“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 代码。

【问题讨论】:

    标签: node.js ethereum truffle


    【解决方案1】:

    在我的情况下,发生此错误是因为合约部署交易的 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).
    

    【讨论】:

      猜你喜欢
      • 2018-07-23
      • 2021-07-01
      • 1970-01-01
      • 2022-07-26
      • 2022-11-13
      • 1970-01-01
      • 1970-01-01
      • 2022-10-16
      • 2019-09-22
      相关资源
      最近更新 更多