I'm trying to make the latest Truffle (3.4.3) and Web3 (1.0.0-beta11) to work together in a React app.
It fails when I try to call myContractInstance.deployed()
import { default as Eth} from 'web3-eth';
import { default as Contract } from 'truffle-contract';
import myContract_artifacts from '../../build/contracts/myContract.json';
...
var eth = new Eth(Eth.givenProvider || "http://localhost:8545");
var myContractDef = Contract(myContract_artifacts);
myContractDef.setProvider( eth.currentProvider);
var myContractInstance = await myContractDef.deployed();
the last line throws an error with localhost http provider (testrpc v4.0.1):
Uncaught (in promise) TypeError: Cannot read property 'apply' of undefined
at Provider.sendAsync (bundle.js:113598)
at RequestManager.sendAsync (bundle.js:121952)
at Object.get [as getNetwork] (bundle.js:23150)
at bundle.js:114052
at Promise (<anonymous>)
at Function.detectNetwork (bundle.js:114043)
at Function.deployed (bundle.js:113991)
at App.componentDidMount (bundle.js:60259)
at bundle.js:68136
at measureLifeCyclePerf (bundle.js:67947)
at bundle.js:68135
at CallbackQueue.notifyAll (bundle.js:39530)
at ReactReconcileTransaction.close (bundle.js:70093)
at ReactReconcileTransaction.closeAll (bundle.js:26044)
at ReactReconcileTransaction.perform (bundle.js:25991)
at batchedMountComponentIntoNode (bundle.js:41397)
at ReactDefaultBatchingStrategyTransaction.perform (bundle.js:25978)
at Object.batchedUpdates (bundle.js:69759)
at Object.batchedUpdates (bundle.js:13827)
at Object._renderNewRootComponent (bundle.js:41590)
at Object._renderSubtreeIntoContainer (bundle.js:41672)
at render (bundle.js:41693)
but also with Metamask (v3.9.0):
Uncaught (in promise) Error: MetamaskInpageProvider - sendAsync not overwritten
at MetamaskInpageProvider.sendAsync (inpage.js:219)
at Provider.sendAsync (bundle.js:113598)
at RequestManager.sendAsync (bundle.js:121952)
at Object.get [as getNetwork] (bundle.js:23150)
at bundle.js:114052
at Promise (<anonymous>)
at Function.detectNetwork (bundle.js:114043)
at Function.deployed (bundle.js:113991)
at App.componentDidMount (bundle.js:60259)
at bundle.js:68136
at measureLifeCyclePerf (bundle.js:67947)
at bundle.js:68135
at CallbackQueue.notifyAll (bundle.js:39530)
at ReactReconcileTransaction.close (bundle.js:70093)
at ReactReconcileTransaction.closeAll (bundle.js:26044)
at ReactReconcileTransaction.perform (bundle.js:25991)
at batchedMountComponentIntoNode (bundle.js:41397)
at ReactDefaultBatchingStrategyTransaction.perform (bundle.js:25978)
at Object.batchedUpdates (bundle.js:69759)
at Object.batchedUpdates (bundle.js:13827)
at Object._renderNewRootComponent (bundle.js:41590)
at Object._renderSubtreeIntoContainer (bundle.js:41672)
I've got the same errors when I try:
myContractDef.deployed().then( function( error, result) { ... } )