[英]Getting error when compiling and deploying ethereum smart contract with Node.js
[英]Getting Error when try to deploy contract from node js using truffle-contract
我遇到錯誤,正在關注此文檔: https : //www.npmjs.com/package/truffle-contract
每當我調用deploy函數時,我都會收到此錯誤。
import Web3 from 'web3';
import propertyContractJson from './contracts/PropertyContract.json';
var provider = new Web3.providers.HttpProvider("http://localhost:8545");
var contract = require("truffle-contract");
var MyContract = contract({
abi: propertyContractJson,
address: '0x0A08a58433108f1a8dF080Ef552f137b2f7b8ce0' // optional
// many more
})
MyContract.setProvider(provider);
var deployed;
MyContract.deployed().then(function(instance) {
deployed = instance;
return instance;
}).then(function(result) {
// Do something with the result or continue with more transactions.
});
以下是調用deploy()方法時出現的錯誤
錯誤:未處理的拒絕節點錯誤:{“消息”:“不支持方法[對象對象]。”,“代碼”:-32000,“數據”:{“堆棧”:“錯誤:不支持方法[對象對象]。\\ n在GethApiDouble.handleRequest(C:\\ Program Files \\ WindowsApps \\ Ganache_2.0.0.0_x64__zh355ej5cj694 \\ app \\ resources \\ app.asar \\ node_modules \\ ganache-core \\ lib \\ subproviders \\ geth_api_double.js:67:16)\\ n在n (C:\\ Program Files \\ WindowsApps \\ Ganache_2.0.0.0_x64__zh355ej5cj694 \\ app \\ resources \\ app.asar \\ node_modules \\ ganache-core \\ node_modules \\ web3-provider-engine \\ index.js:116:18)\\ n在GethDefaults。 handleRequest(C:\\ Program Files \\ WindowsApps \\ Ganache_2.0.0.0_x64__zh355ej5cj694 \\ app \\ resources \\ app.asar \\ node_modules \\ ganache-core \\ lib \\ subproviders \\ gethdefaults.js:15:12)\\ n在下一個(C:\\程序文件\\ WindowsApps \\ Ganache_2.0.0.0_x64__zh355ej5cj694 \\ app \\ resources \\ app.asar \\ node_modules \\ ganache-core \\
問題來自web3的版本,松露當前不支持。 當您安裝Web3時,安裝的版本是1.0.0(測試版),而松露與0.20(穩定版本)一起使用。要解決此問題,請刪除node_modules文件夾並在package.json文件夾中編輯web3的版本,然后運行命令npm install
並在松露中使用> build
命令重建合約。 該API應該可以正常工作。 如果您仍想使用1.0.0版,請您閱讀本文 ,但尚未測試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.