最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

web3,松露,nodejs错误:UnhandledPromiseRejectionWarning

IT培训 admin 11浏览 0评论

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)

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. 暂无评论