1
votes

I am getting error, I am following this documentation: https://www.npmjs.com/package/truffle-contract

Whenever I call deploy function then I received this error.

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

Following is the error I get when deployed() method is called

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\

1

1 Answers

0
votes

The problem comes from the version of web3, it is currently not supported by truffle. When you install Web3, the installed version is 1.0.0 (a beta version) while truffle works with the 0.20 (the stable version) To solve this problem, delete the node_modules folder and edit the version of web3 in the package.json folder, then run the command npm install and rebuild the contracts with > build command in truffle. The API should work. If you still want to use version 1.0.0, I invite you to read this article, I have not tested it yet.