0

Playing around with the gnosis multisig, using truffle-contract to interact with already deployed MultiSigWallet using truffle migrate.

Contents of the file I am trying to run:

var contract = require('truffle-contract');

var fs = require('fs');
var Web3 = require('web3');
var web3 = new Web3('http://localhost:9545');
var provider = new Web3.providers.HttpProvider('http://localhost:9545');

var fileData = fs.readFileSync('./build/contracts/MultiSigWallet.json');
var jsonData = JSON.parse(fileData.toString());

var myContract = contract(jsonData);
myContract.setProvider(provider);

myContract.deployed().then(function(instance) {
        var deployed = instance;
        return deployed.address;
})
.then(function(result) {
        console.log(result);
})
.catch(err => { 
        console.log(err);  
});

When I run using node, get error:

TypeError: Cannot read property 'apply' of undefined
    at Provider.sendAsync (/home/delphi/MultiSigWallet/node_modules/truffle-contract/contract.js:24:36)
    at RequestManager.sendAsync (/home/delphi/MultiSigWallet/node_modules/truffle-contract/node_modules/web3/lib/web3/requestmanager.js:80:19)
    at Object.get [as getNetwork] (/home/delphi/MultiSigWallet/node_modules/truffle-contract/node_modules/web3/lib/web3/property.js:116:33)
    at /home/delphi/MultiSigWallet/node_modules/truffle-contract/contract.js:512:27
    at new Promise (<anonymous>)
    at Function.detectNetwork (/home/delphi/MultiSigWallet/node_modules/truffle-contract/contract.js:503:14)
    at Function.deployed (/home/delphi/MultiSigWallet/node_modules/truffle-contract/contract.js:451:19)
    at Object.<anonymous> (/home/delphi/MultiSigWallet/test.js:14:12)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Function.Module.runMain (module.js:694:10)
    at startup (bootstrap_node.js:204:16)
    at bootstrap_node.js:625:3

The undefined referred to in the error is for myContract.deployed(). I cannot figure out why this is though. Simple console output shows that myContract is not undefined. Can anyone help me figure out what is wrong?

2
  • 1
    Does any of the solutions proposed here(truffle GitHub repo) help you? Commented Nov 1, 2018 at 21:19
  • Changing it to contract.setProvider(provider.currentProvider) results in error that provider is undefined, but I checked it's value and it's not undefined?
    – jojeyh
    Commented Nov 1, 2018 at 22:10

1 Answer 1

0
import contract from 'truffle-contract'

but, node this file will report error 'SyntaxError: Unexpected identifier'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.