gpt4 book ai didi

node.js - 尝试使用 truffle-contract 从 Node js 部署合约时出现错误

转载 作者:太空宇宙 更新时间:2023-11-04 01:30:42 28 4
gpt4 key购买 nike

我收到错误,我正在遵循此文档: https://www.npmjs.com/package/truffle-contract

每当我调用部署函数时,我都会收到此错误。

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.
});

以下是调用Deployment()方法时出现的错误

Error: Unhandled rejectionNode error: {"message":"Method [object Object] not supported.","code":-32000,"data":{"stack":"Error: Method [object Object] not supported.\n at 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 at next (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 at 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 at next (C:\Program Files\WindowsApps\Ganache_2.0.0.0_x64__zh355ej5cj694\app\resources\app.asar\node_modules\ganache-core\

最佳答案

问题来自于web3版本,truffle目前不支持。当您安装Web3时,安装的版本是1.0.0(测试版本),而truffle使用0.20(稳定版本)要解决这个问题,删除node_modules文件夹并编辑package.json文件夹中web3的版本,然后运行命令npm install并在truffle中使用> build命令重建合约。 API 应该可以工作。如果您还想使用1.0.0版本,我邀请您阅读this article ,我还没有测试过。

关于node.js - 尝试使用 truffle-contract 从 Node js 部署合约时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56245575/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com