[英]Ethereum: NodeJS web3 - UnhandledPromiseRejectionWarning: Insufficient funds
[英]web3, truffle, nodejs error : 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 的智能合約函數。我使用 truffle 控制台對其進行了測試,並且它工作正常。 但是當嘗試使用 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.
對這個問題有什么想法嗎?
用const MyContract = artifacts.require("MyContractewCoin")
替換 MyContract 定義
// 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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.