tomusdrw / rust-web3

Ethereum JSON-RPC multi-transport client. Rust implementation of web3 library. ENS address: rust-web3.eth
MIT License
1.45k stars 465 forks source link

Error: Rpc(Error { code: MethodNotFound, message: "Method not found", data: None }) #661

Closed 0xZangetsudev closed 1 year ago

0xZangetsudev commented 2 years ago

Hello, I have tried some examples from this repo, like send private, public tx, call account balance etc but I always get the same error :

Error: Rpc(Error { code: MethodNotFound, message: "Method not found", data: None })

I have tried to put all dependencies inside my cargo toml but it still not working

I run an akula mainnet node in localhost 8545 with http request and its working well with web3 js

haoduoyu commented 1 year ago

I tried to run transaction_public.rs and transaction_private.rs in the example folder and they both work fine, can you describe your process in detail? @0xZangetsudev

songtianyi commented 1 year ago

i'm having same issue when running contract.rs example

use hex_literal::hex;
use web3::{
    contract::{Contract, Options},
    types::U256,
};

#[tokio::main]
async fn main() -> web3::contract::Result<()> {
    let _ = env_logger::try_init();
    let http = web3::transports::Http::new("http://localhost:9933")?;
    let web3 = web3::Web3::new(http);

    let my_account = hex!("d028d24f16a8893bd078259d413372ac01580769").into();
    // Get the contract bytecode for instance from Solidity compiler
    let bytecode = include_str!("./res/contract_token.code").trim_end();
    // Deploying a contract
    let contract = Contract::deploy(web3.eth(), include_bytes!("../src/contract/res/token.json"))?
        .confirmations(0)
        .options(Options::with(|opt| {
            opt.value = Some(5.into());
            opt.gas_price = Some(5.into());
            opt.gas = Some(3_000_000.into());
        }))
        .execute(
            bytecode,
            (U256::from(1_000_000_u64), "My Token".to_owned(), 3u64, "MT".to_owned()),
            my_account,
        )
        .await?;

    let result = contract.query("balanceOf", (my_account,), None, Options::default(), None);
    // Make sure to specify the expected return type, to prevent ambiguous compiler
    // errors about `Detokenize` missing for `()`.
    let balance_of: U256 = result.await?;
    assert_eq!(balance_of, 1_000_000.into());

    // Accessing existing contract
    let contract_address = contract.address();
    let contract = Contract::from_json(
        web3.eth(),
        contract_address,
        include_bytes!("../src/contract/res/token.json"),
    )?;

    let result = contract.query("balanceOf", (my_account,), None, Options::default(), None);
    let balance_of: U256 = result.await?;
    assert_eq!(balance_of, 1_000_000.into());

    Ok(())
}

I did not change anything except the node port