trufflesuite / trufflesuite.github.io

Staging Repo of Build Artifacts for Truffle Suite. Find the source at https://github.com/trufflesuite/trufflesuite.com
https://www.trufflesuite.com
34 stars 161 forks source link

Testing in ropsten network (in infura) with truffle.js gives me this error #165

Closed gerstaro closed 6 years ago

gerstaro commented 6 years ago

root@ubuntu-4gb-nyc3-01:~# truffle migrate --network ropsten (node:14686) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: this.provider.sendAsync is not a function (node:14686) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. Using network 'ropsten'.

Running migration: 1_initial_migration.js

**After that it exits to

root@ubuntu-4gb-nyc3-01:~#

without running 2_deploy_contracts.js**

My truffle.js looks like the following :

var bip39 = require("bip39");
var hdkey = require('ethereumjs-wallet/hdkey');
var ProviderEngine = require("web3-provider-engine");
var WalletSubprovider = require('web3-provider-engine/subproviders/wallet.js');
var Web3Subprovider = require("web3-provider-engine/subproviders/web3.js");
var Web3 = require("web3");
// Get our mnemonic and create an hdwallet
var mnemonic = "twelve words we can find in metamask settings reveal seed words blabla";
var hdwallet = hdkey.fromMasterSeed(bip39.mnemonicToSeed(mnemonic));
// Get the first account using the standard hd path.
var wallet_hdpath = "m/44'/60'/0'/0/";
var wallet = hdwallet.derivePath(wallet_hdpath + "0").getWallet();
var address = "0x" + wallet.getAddress().toString("hex");
console.log(address);
var providerUrl = "https://ropsten.infura.io/mytoken";
var engine = new ProviderEngine();
engine.addProvider(new WalletSubprovider(wallet, {}));
engine.addProvider(new Web3Subprovider(new Web3.providers.HttpProvider(providerUrl)));
engine.start(); // Required by the provider engine.
module.exports = {
  networks: {
    ropsten: {
      network_id: 3,    // Official ropsten network id
      provider: engine, // Use our custom provider
      from: address,     // Use the address we derived
      gas: 3000000
    }
  },
  rpc: {
    // Use the default host and port when not using ropsten
    host: "my-server-ip-goes-here",
    port: 8545
  }
  };

My 2_deploy_contracts.js looks like the following ;

var SafeMath = artifacts.require("./SafeMath.sol");
var RedPillToken = artifacts.require("./MyToken.sol");
var Crowdsale = artifacts.require("./Crowdsale.sol");

module.exports = function(deployer) {

    var owner = web3.eth.accounts[0];
    var wallet = web3.eth.accounts[1];

    console.log("Owner address: " + owner); 
    console.log("Wallet address: " + wallet);   

    deployer.deploy(SafeMath, { from: owner });
    deployer.link(SafeMath,MyToken);
    return deployer.deploy(MyToken, { from: owner }).then(function() {
        console.log("MyToken address: " + MyToken.address);
        return deployer.deploy(Crowdsale, MyToken.address, wallet, { from: owner }).then(function() {
            console.log("Crowdsale address: " + Crowdsale.address);
            return MyToken.deployed().then(function(coin) {
                return coin.owner.call().then(function(owner) {
                    console.log("MyToken owner : " + owner);
                    return coin.transferOwnership(Crowdsale.address, {from: owner}).then(function(txn) {
                        console.log("MyToken owner was changed: " + Crowdsale.address);     
                    });
                })
            });
        });
    });
};

Where will I find this.provider.sendAsync function?

I m using node : v8.2.1 and Ubuntu 16.04

I m really stuck with this. Any help would be appreciated. Thanks

N.B. I created a 12 word mnemonic from metamask plugin from chrome. and then tried to deploy the conract in ropsten again after updating the truffle.js with the new mnemonic. Again the same error :UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: this.provider.sendAsync is not a function (node:22993) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

okwme commented 6 years ago

i'm having the same error after following this tutorial.

(node:38684) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: this.provider.sendAsync is not a function
(node:38684) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:38685) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: this.provider.sendAsync is not a function
(node:38685) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Using network 'ropsten'.
okwme commented 6 years ago

found one solution is to install older versions of the packages: $ npm install ethereumjs-wallet bip39 web3-provider-engine@8.6.1 web3@0.18.4 zeppelin-solidity --save

gerstaro commented 6 years ago

thanks will try this out.

On 9/4/17, billy notifications@github.com wrote:

found one solution is to install older versions of the packages: $ npm install ethereumjs-wallet bip39 web3-provider-engine@8.6.1 web3@0.18.4 zeppelin-solidity --save

-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/trufflesuite/trufflesuite.github.io/issues/165#issuecomment-326831474

dryruner commented 6 years ago

I don't quite like this solution, as current version is 13.3.3......

dryruner commented 6 years ago

All right, it seems the failure has nothing to do with web3-provider-engine, it's related to web3. I installed web3-provider-engine (@latest version), but with web3@0.18.4, the issue is gone!

bmmpxf commented 6 years ago

Hi there. This repo is for the website, not Truffle the application. For questions of this nature, we recommend logging into our Gitter channel and asking for help there.

If you think there is a bug in Truffle, you can raise an issue on the main Truffle issue tracker. Thanks!

Ankarrr commented 6 years ago

If you follow this tutorial, try to change the provider declaration to:

provider: new HDWalletProvider(mnemonic, "https://ropsten.infura.io/<Your Token>"),

It fixes TypeError: this.provider.sendAsync is not a function for me.

celeduc commented 6 years ago

A similar issue exists with truffle-contract and MetaMask, for which a workaround is documented here: https://github.com/trufflesuite/truffle-contract/issues/57#issuecomment-379877709