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 的智能合约函数。我使用 truffle 控制台对其进行了测试,它可以正常工作。但是当尝试使用 nodejs 获得相同的结果时,它会崩溃并给出这两个错误:
(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.
关于这个问题的任何想法?