![](/img/trans.png)
[英]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.