1

I am trying to deploy smart contract using ledger wallet. But i keep getting the error cant subscribe to new header. However i get the transaction hash but cant receive the contract instance and receipt.

enter image description here

var myContract = new my_web3.eth.Contract(this.state.abi);
        myContract.deploy({
            from: this.state.defaultAddr,
            data:this.state.byteCode

        })
        .send({
            from: this.state.defaultAddr,
            gas: 1500000,
            gasPrice: '30000000'
        })
        .on('error',error=>{

            console.log(error)
            this.setState({
             errors:error
            ,infoHidden:true
            ,errorHidden:false
            })
        })
        .on('transactionHash', transactionHash=>{ 
         console.log(transactionHash) })
        .on('receipt',receipt=>{
           console.log(receipt) // contains the new contract address
        })
        .on('confirmation', function(confirmationNumber, receipt){ 
          console.log(confirmationNumber) })
        .then(newContractInstance=>{
            console.log(newContractInstance) // instance with the new 
                 contract address







                this.setState({
                Contract:newContractInstance,
                infoHidden:false,
                errorHidden:true})
            console.log("Contract 
            Address"+newContractInstance.options.address);
            this.props.history.push({
                pathname:'/save',
                state:{
                // ABI:response.data.data.abi,
                // byteCode:response.data.data.byteCode,
                ContractAddress:newContractInstance.options.address,
                ABI:this.state.abi,
                    }  
                    })


        })

Connection Snippet

   var my_web3
    let account;
    const rpcUrl = "https://rinkeby.infura.io/";

   const use_ledger =localStorage.walletAccessMechanismType;
   console.log(use_ledger)
    if(use_ledger =="ledger")
    {
    const engine = new ProviderEngine();
    const getTransport = () => TransportU2F.create();
    const ledger = createLedgerSubprovider(getTransport, {
    networkId: 4, // 3 == Ropsten testnet
    });
    engine.addProvider(ledger);
    engine.addProvider(new RpcSubprovider({ rpcUrl }));
   engine.start();
   my_web3 = new Web3(engine); 
  } else if(typeof(web3) === 'undefined') {
    my_web3 = new Web3(new Web3.providers.HttpProvider(rpcUrl));
  } else {
     my_web3 = new Web3(window.web3.currentProvider);    
    }
7
  • How do you setup your web3 instance? It seems you are using web3 v1.0, in that version to subscribe to events you have to use the websocket version of infura, because RPC version does not support polling events.
    – Ismael
    Commented Oct 19, 2018 at 4:24
  • I have added the connection snipped above @Ismael Commented Oct 19, 2018 at 7:42
  • If you could refer me some useful material that'd be great.. i'm new to ledger. however i tried the same approach with a demo app and it worked perfectly but now it's giving errors with the new one. Commented Oct 19, 2018 at 7:46
  • It is explained in the answers to this question ethereum.stackexchange.com/questions/25451/…, one of them provides an example how to use with websockets.
    – Ismael
    Commented Oct 19, 2018 at 16:14
  • Tried it but i still cant deploy my contract using nano ledger .. how ever every thing works well when im using metamask Commented Oct 20, 2018 at 12:08

1 Answer 1

0

Sorry for the late response. My issue was solved it seemed that infura only allows RPC while through ledgerhq library i wasnt able to do that or due to web3. So all i had to do was instead of injecting my ledgerhq provider,i used infura default provider and i was able to solve the issue. any way thank you very much for your support

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.