Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

agent err: DerKeyLengthMismatch { expected: 133, actual: 222 } #541

Open
q2333gh opened this issue Mar 25, 2024 · 0 comments
Open

agent err: DerKeyLengthMismatch { expected: 133, actual: 222 } #541

q2333gh opened this issue Mar 25, 2024 · 0 comments

Comments

@q2333gh
Copy link

q2333gh commented Mar 25, 2024

dfx start is running:
and dfx deploy backend ok
code in canister:

#[query(guard = "user_owner_guard")]
pub fn greet_test()->String{
  ic_cdk::println!("got greet_test() call");
  return "hello agent!".to_string();
}
async fn greet_test(agent: Agent, canister_id: Principal) -> String {
  let response = agent
    .query(&canister_id, "greet_test")
    .with_arg(candid::encode_one(()).unwrap())
    .call()
    .await;
  match response {
    Ok(data) => {
      let ret = String::from_utf8(data).unwrap();
      println!("{}", ret);
      return ret;
    }
    Err(e) => {
      let ret = format!("####An error occurred: {:?}", e);
      println!("{}", ret);
      return ret;
    }
  }
}

running in ic mode perfect ok. but local agent fails:

async fn init_agent() -> (Principal, Agent, String) {
  let controller = String::from("btwlz");
  let args: Vec<String> = env::args().collect();
  let online_mode = &args[1];

  let url_local = String::from("http://127.0.0.1:40010");
  let url_ic = String::from("https://ic0.app/");

  let canister_id_local =
    Principal::from_text("bkyz2-fmaaa-aaaaa-qaaaq-cai").unwrap();
  let canister_id_ic =
    Principal::from_text("v7g7o-oiaaa-aaaag-qcj3q-cai").unwrap();
  let url;
  let canister_id;

  if online_mode == "0" {
    println!("local network mode");
    url = url_local;
    canister_id = canister_id_local;
  } else if online_mode == "1" {
    println!("ic network mode");
    url = url_ic;
    canister_id = canister_id_ic;
  } else {
    panic!("args input err!!");
  }

  // !INFO this need use input passwd in terminal if have passwd. takes about 3s
  // to run
  let identity = get_dfx_identity(&controller);
  let agent = build_ic_agent(url, identity).await;
  (canister_id, agent, online_mode.to_string())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant