Developing with Hardhat, Truffle and Foundry

Hardhat, Truffle and Foundry can use a Tatum RPC URL from their config file to build, sign and broadcast smart contract transactions.

Hardhat, Foundry, Truffle (legacy), and other similar frameworks can help you with the development and testing of Smart Contracts.

The framework can work as an RPC wrapper, so Developers can write for example contract.connect(myWallet).foo() - and the framework builds a transaction to the contract address, executing function foo() from the myWallet address, signs it, and broadcasts it using the RPC.

🚧

Truffle is a legacy tool. ConsenSys sunset Truffle and Ganache in 2023, and their repositories are archived. For new projects, use Hardhat or Foundry.

Good to know

  • Each of these frameworks has a config file, where you can pass a specific Tatum RPC URL.
  • Send your API key in the x-api-key header. See Authentication for the other supported methods.

Hardhat

In Hardhat 3, add the Tatum RPC URL as an http network in hardhat.config.ts and pass the API key in httpHeaders. This example reads the key from the TATUM_API_KEY environment variable and the deployer's private key from the SEPOLIA_PRIVATE_KEY configuration variable:

import { configVariable, defineConfig } from "hardhat/config";

export default defineConfig({
  networks: {
    sepolia: {
      type: "http",
      url: "https://ethereum-sepolia.gateway.tatum.io",
      httpHeaders: { "x-api-key": process.env.TATUM_API_KEY ?? "" },
      accounts: [configVariable("SEPOLIA_PRIVATE_KEY")],
    },
  },
});

Then run your scripts with --network sepolia. See the Hardhat configuration reference.

Foundry

In Foundry, name the Tatum RPC URL in the [rpc_endpoints] table of foundry.toml, and send the API key with --rpc-headers or the ETH_RPC_HEADERS environment variable:

[rpc_endpoints]
sepolia = "https://ethereum-sepolia.gateway.tatum.io"
export ETH_RPC_HEADERS="x-api-key: {YOUR_API_KEY}"
cast block-number --rpc-url sepolia

See the Foundry configuration reference.

🚧

Tatum does not troubleshoot issues on 3rd party code or tools. Please refer to each framework documentation site, community resources, and Support services.


Did this page help you?