0

On etherjs you can send a custom header as follows.

import { ethers } from "ethers";

const connection = {
    url: "https://custom.rpc.url.com",
    headers: [ "Authorization": "SOME_API_KEY" ],
};      
const provider = new ethers.providers.JsonRpcProvider(connection);

async function main() {
    const blockNumber = await provider.getBlockNumber();
    console.log(blockNumber);
}

On hardhat you can send it as follows.

const config: HardhatUserConfig = {
  solidity: "0.8.19",
  networks: {
    // For localhost network
    hardhat: {
      chainId: 1337,
    },
    customNetwork: {
      chainId: chainId,
      url: "https://custom.rpc.url.com",
      httpHeaders: {
        "Authorization": SOME_API_KEY
      }
      accounts: [privateKey],
    }
  }
};

How do I do something similar in foundry?

1 Answer 1

0

An option to set httpHeaders while defining rpc_endpoints doesn't seem to be available in Foundry yet.

But, if your RPC-URL supports the API-key to be appended at the end of the url. Then, you can define the same in the foundry.toml file, like:

[rpc_endpoints]
customNetwork = "https://custom.rpc.url.com/${SOME_API_KEY}"

Provided that SOME_API_KEY is defined as an environment variable.

Then, you can use the same while running any command, by using it with the --rpc-url flag like:

forge create ContractName --rpc-url customNetwork --interactive

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.