最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

web3,松露,nodejs错误:UnhandledPromiseRejectionWarning

网站源码admin19浏览0评论

web3,松露,nodejs错误:UnhandledPromiseRejectionWarning

web3,松露,nodejs错误:UnhandledPromiseRejectionWarning

var     web3            = require('web3'),
    contract        = require('truffle-contract'),
    path            = require('path'),
    MyContractJSON  = require(path.join(__dirname, '../tru_dir/build/contracts/NewCoin.json'));
var     provider        = new web3.providers.HttpProvider("http://localhost:8545");

var     MyContract      = contract(MyContractJSON);

MyContract.setProvider(provider);
MyContract.deployed().then(function(instance){
return instance.returnfive();
})

.then(function(result) {
console.log(result);
}, function(error) {
console.log(error);
});

我设置此代码以调用返回5的智能合约函数。我用松露控制台进行了测试,它可以正常工作。但是,当尝试使用nodejs获得相同的结果时,它崩溃并给出这2个错误:

(node:6227) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Cannot read property 'apply' of undefined
(node:6227) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

对这个问题有任何想法吗?

回答如下:

将MyContract定义替换为const MyContract = artifacts.require("MyContractewCoin")

// You are missing this step before invoking deployer
await deployer.deploy(MyContract) 

const dMyContract = await MyContract.deployed() 
// now you can do stuff like 
let result = await dMyContract.someContractFunction(args)
发布评论

评论列表(0)

  1. 暂无评论