foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.28k stars 1.75k forks source link

bug(`cast`): `error code -32602: unknown account` #8799

Open emnul opened 2 months ago

emnul commented 2 months ago

I would like to be able to use cast to send transactions to my local reth dev node; however, reth expects a JWT auth header to be set on the HTTP request. Currently, there's no way to create a JWT authenticated request to an RPC URL via cast.

onbjerg commented 2 months ago

This belongs in the foundry repo, not the book repo, moving it

yash-atreya commented 2 months ago

You can pass your jwt secret using --jwt-secret OR set the env variable ETH_RPC_JWT_SECRET which is used to generate the relevant auth token

emnul commented 2 months ago

Hey @yash-atreya I realized that I was querying the wrong port number and I don't actually need a JWT auth header to query the JSON RPC http server that's opened by my Reth node. However, I still can't seem to get cast to work with my local dev node.

Steps to repro:

  1. Clone reth repo
  2. Run cargo run --bin reth -- node --dev
  3. After the node is started, in a separate terminal run
    cast send --rpc-url 'http://localhost:8545' --value 13361851371947497370023 --from 0x14dC79964da2C08b23698B3D3cc7Ca32193d9955 --mnemonic-passphrase "test test test test test test test test test test test junk" --unlocked 0x0000000000000000000000000000000000000000
  4. Observe Error: server returned an error response: error code -32602: unknown account

I'm using the default reth genesis file for my dev node:

{
  "config": {
    "chainId": 1,
    "daoForkSupport": false,
    "terminalTotalDifficultyPassed": false
  },
  "nonce": "0x0",
  "timestamp": "0x6490fdd2",
  "extraData": "0x",
  "gasLimit": "0x1c9c380",
  "difficulty": "0x0",
  "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x0000000000000000000000000000000000000000",
  "alloc": {
    "0x14dc79964da2c08b23698b3d3cc7ca32193d9955": {
      "balance": "0xd3c21bcecceda1000000"
    },
    "0x15d34aaf54267db7d7c367839aaf71a00a2c6a65": {
      "balance": "0xd3c21bcecceda1000000"
    },
    "0x1cbd3b2770909d4e10f157cabc84c7264073c9ec": {
      "balance": "0xd3c21bcecceda1000000"
    },
    "0x23618e81e3f5cdf7f54c3d65f7fbc0abf5b21e8f": {
      "balance": "0xd3c21bcecceda1000000"
    },
    "0x2546bcd3c84621e976d8185a91a922ae77ecec30": {
      "balance": "0xd3c21bcecceda1000000"
    },
    "0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc": {
      "balance": "0xd3c21bcecceda1000000"
    },
    "0x70997970c51812dc3a010c7d01b50e0d17dc79c8": {
      "balance": "0xd3c21bcecceda1000000"
    },
    "0x71be63f3384f5fb98995898a86b02fb2426c5788": {
      "balance": "0xd3c21bcecceda1000000"
    },
    "0x8626f6940e2eb28930efb4cef49b2d1f2c9c1199": {
      "balance": "0xd3c21bcecceda1000000"
    },
    "0x90f79bf6eb2c4f870365e785982e1f101e93b906": {
      "balance": "0xd3c21bcecceda1000000"
    },
    "0x976ea74026e726554db657fa54763abd0c3a0aa9": {
      "balance": "0xd3c21bcecceda1000000"
    },
    "0x9965507d1a55bcc2695c58ba16fb37d819b0a4dc": {
      "balance": "0xd3c21bcecceda1000000"
    },
    "0xa0ee7a142d267c1f36714e4a8f75612f20a79720": {
      "balance": "0xd3c21bcecceda1000000"
    },
    "0xbcd4042de499d14e55001ccbb24a551f3b954096": {
      "balance": "0xd3c21bcecceda1000000"
    },
    "0xbda5747bfd65f08deb54cb465eb87d40e51b197e": {
      "balance": "0xd3c21bcecceda1000000"
    },
    "0xcd3b766ccdd6ae721141f452c550ca635964ce71": {
      "balance": "0xd3c21bcecceda1000000"
    },
    "0xdd2fd4581271e230360230f9337d5c0430bf44c0": {
      "balance": "0xd3c21bcecceda1000000"
    },
    "0xdf3e18d64bc6a983f673ab319ccae4f1a57c7097": {
      "balance": "0xd3c21bcecceda1000000"
    },
    "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266": {
      "balance": "0xd3c21bcecceda1000000"
    },
    "0xfabb0ac9d68b0b445fb7357272ff202c5651694a": {
      "balance": "0xd3c21bcecceda1000000"
    }
  },
  "number": "0x0"
}

The following alloy script works fine:

use alloy::{
    network::{EthereumWallet, TransactionBuilder},
    primitives::{address, TxHash, U256},
    providers::{Provider, ProviderBuilder},
    rpc::types::TransactionRequest,
};
use alloy_signer_local::{coins_bip39::English, MnemonicBuilder};
use eyre::Result;

#[tokio::main]
async fn main() -> Result<()> {
    let rpc_url = "http://localhost:8545".parse()?;

    let signer = MnemonicBuilder::<English>::default()
        .phrase("test test test test test test test test test test test junk")
        .build()?;
    let wallet = EthereumWallet::from(signer);

    // Create a provider with the HTTP transport using the `reqwest` crate.
    let provider = ProviderBuilder::new()
        .with_recommended_fillers()
        .wallet(wallet)
        .on_http(rpc_url);

    let vitalik = address!("0000000000000000000000000000000000000000");
    let tx = TransactionRequest::default()
        .with_to(vitalik)
        .with_value(U256::from(100));

    // Send the transaction, the nonce (0) is automatically managed by the provider.
    let builder = provider.send_transaction(tx.clone()).await?;
    let node_hash = *builder.tx_hash();
    let pending_tx = provider
        .get_transaction_by_hash(node_hash)
        .await?
        .expect("Pending transaction not found");

    println!("Pending transaction... {}", pending_tx.hash);

    let tx_conf: TxHash = builder.watch().await.unwrap();

    // Wait for the transaction to be included and get the receipt.
    let receipt = provider.get_transaction_receipt(tx_conf).await?.unwrap();

    println!(
        "Transaction included in block {}",
        receipt.block_number.expect("Failed to get block number")
    );

    Ok(())
}

Am I missing in my cast command? Is this a known limitation?