Trying out the `ic-web3` library

I’m trying to work with ic-web3 but if fails.

I tried calling get_canister_addr
but I’m getting errors:

❯ dfx canister call eth get_canister_addr
(
  variant {
    Err = "Failed to call ecdsa_public_key Unable to route management canister request ecdsa_public_key: EcdsaKeyError(\"Requested ECDSA key: Secp256k1:test_key_1100, existing keys: [Secp256k1:dfx_test_key]\")"
  },
)

I changed derivation path, keyname. will I’m getting the same error…

const PATH: &[u8] = b"WALLET";
const KEY_NAME: &str = "HUGDDJ";

other function fails too

 dfx canister call eth get_eth_gas_price
(
  variant {
    Err = "get gas price failed: The http_request resulted into error. RejectionCode: SysTransient, Error: Failed to connect: error trying to connect: dns error: failed to lookup address information: nodename nor servname provided, or not known"
  },
)

also other questions:

  • how does canister handles multiple number of address in single canister?
  • with the same derivation path and key, can I generate the same address every time? if yes, how is this protected from hacks?

I see that you try to use a key with name test_key_1100, but this key does not exist. Try using test_key_1 for testing purposes on mainnet, or key_1 for production.

1 Like

Hey @pramitgaha,

Could you give a bit more context what you mean here? If you want to control multiple ETH addresses / ECDSA keys, then you can do this with multiple key derivation paths.

What’s the address of the RPC provider you are using? Do other calls work?

(CC: @ccyanxyz)

As Manu said, try use a different key name, seems like you are using a local replica, so the name should be dfx_test_key.
The second issue is a network problem, maybe try a different RPC url

I tried most of the nodes provided by dieter. I’m getting the error on all nodes.

I understood the first error was generated generated due to invalid key, what about the another error?

@ccyanxyz
I tried all the nodes marked YES from the list of @dieter.sommer.
I’m just trying to get the gas price and here is my code:

use ic_cdk_macros::*;
use candid::{candid_method, export_service};
use ic_web3::{transports::ICHttp, Web3};

const URL: &str = "";

#[update]
#[candid_method(update)]
async fn get_eth_gas_price() -> Result<String, String> {
    let w3 = match ICHttp::new(URL, None, None){
        Ok(v) => Web3::new(v),
        Err(e) => return Err(e.to_string())
    };
    let gas_price = w3.eth().gas_price().await.map_err(|e| format!("{:?}", e))?;
    Ok(format!("{:?}", gas_price))
}

here is the report:

CloudFlare - tried on different library called: ic-eth-rpc : variant {
    Err = opt variant {
      HttpRequestError = record {
        code = 2 : nat32;
        message = "Failed to connect: error trying to connect: dns error: failed to lookup address information: nodename nor servname provided, or not known";
      }
    }
  },
AllNodes - variant {
    Err = "Transport(Message(\"The http_request resulted into error. RejectionCode: SysTransient, Error: Failed to connect: error trying to connect: dns error: failed to lookup address information: nodename nor servname provided, or not known\"))"
  },
Alchemy - variant {
    Err = "Transport(Message(\"The http_request resulted into error. RejectionCode: SysTransient, Error: Failed to connect: error trying to connect: dns error: failed to lookup address information: nodename nor servname provided, or not known\"))"
  },
FlashBots - variant {
    Err = "Transport(Message(\"The http_request resulted into error. RejectionCode: SysTransient, Error: Failed to connect: error trying to connect: dns error: failed to lookup address information: nodename nor servname provided, or not known\"))"
  },
BlastAPI - variant {
    Err = "Transport(Message(\"The http_request resulted into error. RejectionCode: SysTransient, Error: Failed to connect: error trying to connect: dns error: failed to lookup address information: nodename nor servname provided, or not known\"))"
  },
Flux - paid one, skipped
NowNodes - variant {
    Err = "Transport(Message(\"The http_request resulted into error. RejectionCode: SysTransient, Error: Failed to connect: error trying to connect: dns error: failed to lookup address information: nodename nor servname provided, or not known\"))"
  },
ankr - variant {
    Err = "Transport(Message(\"The http_request resulted into error. RejectionCode: SysTransient, Error: Failed to connect: error trying to connect: dns error: failed to lookup address information: nodename nor servname provided, or not known\"))"
  },
Gateway - variant {
    Err = "Transport(Message(\"The http_request resulted into error. RejectionCode: SysTransient, Error: Failed to connect: error trying to connect: dns error: failed to lookup address information: nodename nor servname provided, or not known\"))"
  },
ChainStack - asks for credit card info, skipped

tried other apis too:
I’m getting the same error. looks like the problem is from my side.
I’m on Mac M1(ventura). does anyone knows how to configure dns?

also:
here is my etc/hosts

❯ cat /etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1	localhost
255.255.255.255	broadcasthost
::1             localhost

Hi @pramitgaha!

Have you been able to figure out what the problem was? In case, it is something on our side or the list of nodes, we would like to fix this. If it’s on your side, which you mentioned might be the case, I hope you can solve it.

Once you have figured out whether the problem was caused by your system or is something that needs to be fixed on our side, can you please update this forum post so we know and can either fix things or know that it’s not an issue on our side.

Thank you!

@dieter.sommer
I tried writing a simple rust program to make an api call, it succeed.

use reqwest;
use std::collections::HashMap;
use std::error::Error;
use std::time::Duration;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let mut map = HashMap::new();
    map.insert("id", "1");
    map.insert("jsonrpc", "2.0");
    map.insert("method", "eth_gasPrice");
    let client = reqwest::Client::new();
    let doge = client
        .post("https://eth-mainnet.g.alchemy.com/v2/pzwcM4mAWDcpf42lWDpw39erqssuFzDG")
        .json(&map)
        .header("Accept", "application/json").header("content-type", "application/json")
        .timeout(Duration::from_secs(3))
        .send()
        .await?
        .text()
        .await?;
    println!("{:}", doge);
    Ok(())
}

Output:

{"jsonrpc":"2.0","id":"1","result":"0x3852186f3"}

I asked about this issue to someone, he replied the issue might be with the custom environment.