Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Implications failed: fork.headers -> url #2627

Open
sebastian-alpha opened this issue Mar 18, 2022 · 3 comments
Open

Implications failed: fork.headers -> url #2627

sebastian-alpha opened this issue Mar 18, 2022 · 3 comments

Comments

@sebastian-alpha
Copy link

sebastian-alpha commented Mar 18, 2022

I am trying to run the following command:

ganache-cli --fork.url=https://mainnet-nethermind.blockscout.com --fork.headers=["User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36"]

but get the following error messages:

Implications failed:
 fork.headers -> url

Is there an error with my command and if so, may I have an example of how I can specify a fork url as well as headers?

I'm using ganache v7.0.3 (@ganache/cli: 0.1.4, @ganache/core: 0.1.4)

@davidmurdoch
Copy link
Member

Thanks for reporting this. It looks like there is a bug in the headers+url relationship check.

@davidmurdoch
Copy link
Member

In the meantime you can start ganache programmatically with this script:

// save as ganache.js

const ganache = require( < PATH TO GANACHE, or just "ganache"  if installed in your local node_modules>);
const WEI = 1000000000000000000n;

const server = ganache.server({
   // PUT YOUR GANACHE OPTIONS HERE:
    fork: {
        url: "https://mainnet-nethermind.blockscout.com",
        headers: {"User Agent": "Your User Agent"}
    }
});

server.listen(8545, () => {
    const provider = server.provider;
    const liveOptions = provider.getOptions();
    const accounts = provider.getInitialAccounts();
  
    const addresses = Object.keys(accounts);
    const logs = [];
    logs.push("");
    logs.push("Available Accounts");
    logs.push("==================");
    if (addresses.length > 0) {
      addresses.forEach(function (address, index) {
        const balance = accounts[address].balance;
        const strBalance = balance / WEI;
        const about = balance % WEI === 0n ? "" : "~";
        let line = `(${index}) ${address} (${about}${strBalance} ETH)`;
  
        if (!accounts[address].unlocked) {
          line += " 🔒";
        }
  
        logs.push(line);
      });
  
      logs.push("");
      logs.push("Private Keys");
      logs.push("==================");
  
      addresses.forEach(function (address, index) {
        logs.push(`(${index}) ${accounts[address].secretKey}`);
      });
  
      if (liveOptions.wallet.accountKeysPath != null) {
        logs.push("");
        logs.push(
          `Accounts and keys saved to ${liveOptions.wallet.accountKeysPath}`
        );
      }
    } else {
      logs.push("(no accounts unlocked)");
    }
  
    if (liveOptions.wallet.accounts == null) {
      logs.push("");
      logs.push("HD Wallet");
      logs.push("==================");
      logs.push(`Mnemonic:      ${liveOptions.wallet.mnemonic}`);
      logs.push(
        `Base HD Path:  ${
          liveOptions.wallet.hdPath.join("/") + "/{account_index}"
        }`
      );
    }
  
    if (liveOptions.miner.defaultGasPrice) {
      logs.push("");
      logs.push("Default Gas Price");
      logs.push("==================");
      logs.push(liveOptions.miner.defaultGasPrice.toBigInt().toString());
    }
  
    if (liveOptions.miner.blockGasLimit) {
      logs.push("");
      logs.push("BlockGas Limit");
      logs.push("==================");
      logs.push(liveOptions.miner.blockGasLimit.toBigInt().toString());
    }
  
    if (liveOptions.miner.callGasLimit) {
      logs.push("");
      logs.push("Call Gas Limit");
      logs.push("==================");
      logs.push(liveOptions.miner.callGasLimit.toBigInt().toString());
    }
  
    if (liveOptions.fork.network || liveOptions.fork.url) {
      logs.push("");
      logs.push("Forked Chain");
      logs.push("==================");
      let location;
      if (liveOptions.fork.network) {
        location = `Ethereum ${capitalizeFirstLetter(
          liveOptions.fork.network.replace("goerli", "görli")
        )}, via 丕Infura`;
      } else {
        location = (liveOptions.fork.url).toString();
      }
  
      logs.push(`Location:        ${location}`);
      logs.push(
        `Block:           ${liveOptions.fork.blockNumber.toString()}`
      );
      logs.push(
        `Network ID:      ${liveOptions.chain.networkId.toString()}`
      );
      logs.push(`Time:            ${new Date().toString()}`);
  
      if (liveOptions.fork.requestsPerSecond !== 0) {
        logs.push(
          `Requests/Second: ${
            liveOptions.fork.requestsPerSecond.toString()
          }`
        );
      }
    }
  
    logs.push("");
    logs.push("Chain Id");
    logs.push("==================");
    logs.push(liveOptions.chain.chainId.toString());
  
    logs.push("");
    logs.push("RPC Listening on localhost:8545");
    console.log(logs.join("\n"));
});

to run it:

node ganache.js

Let me know if that works for you.

@davidmurdoch
Copy link
Member

I think we should (temporarily?) remove our use of implies in our options, as a) it's broken, and b) the yargs error message isn't descriptive enough.

It's broken because: our options are strongly typed and expect namespace-less option names (implies: ["url"] instead of implies: ["fork.url"]) but yargs needs the namespace here. Fixing it correctly will take longer and doesn't add much value above just not using our implies feature. This means we do NOT want to close this issue after removing the use of implies, as we should probably implement it properly in the future.

@davidmurdoch davidmurdoch moved this to Inbox in Ganache Jul 19, 2022
@davidmurdoch davidmurdoch moved this from Inbox to Backlog in Ganache Jul 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Status: Backlog
Development

No branches or pull requests

2 participants