Agent.query QueryFields example


I am trying to use agent.query to query a canister from typescript front-end in react native. I could not find any example of how it should be. Any help is much appreciated.
This is what I am trying to achieve: call test method of a canister from front-end using Http call. Specifically instead of ??? in the code below, I am not sure what to put as a valid QueryFields.

const authClient = await AuthClient.create();
    const identity = authClient.getIdentity();
    const agent = new HttpAgent({
        host: '',
    const canisterId = Principal.fromText('4k2wq-cqaaa-aaaab-qac7q-cai');
    agent.query(canisterId, <????????>, identity, ).then((res)=>{

to be more specific, I am having problem understandign arg parameter in queryFields

const queryData = {
        methodName: 'greet',
        arg: ??? how to build this?

Does your canister have a candid interface? The pattern we tend to use is to generate javascript declaration files from the .did file, which we then use with an abstraction of @dfinity/agent -Actor.createActor() so you don’t need to write the query manually

1 Like

yes I understand that approach, but wanted to see if there is a way to go directly with Http request approach? and if yes, how

It’s hard to answer in the abstract. You can inspect the source code of agent, or if you provide the interface you’re targeting I might be able to assemble it for you

1 Like