Hmmm, I had a look at the examples but I’m still struggling to find a way for my problem… Following my artefacts:
declarations/backend.did.d.ts:
import type { Principal } from '@dfinity/principal';
import type { ActorMethod } from '@dfinity/agent';
export interface Secret {
'id' : bigint,
'url' : [] | [string],
'username' : [] | [string],
'date_created' : bigint,
'password' : [] | [string],
'name' : string,
'notes' : [] | [string],
'category' : SecretCategory,
'date_modified' : bigint,
}
export interface _SERVICE {
'add_user_secret' : ActorMethod<[Secret], Result>,
}
declarations/backend.did.js:
export const idlFactory = ({ IDL }) => {
const Secret = IDL.Record({
'id' : IDL.Nat,
'url' : IDL.Opt(IDL.Text),
'username' : IDL.Opt(IDL.Text),
'date_created' : IDL.Nat64,
'password' : IDL.Opt(IDL.Text),
'name' : IDL.Text,
'notes' : IDL.Opt(IDL.Text),
'category' : SecretCategory,
'date_modified' : IDL.Nat64,
});
return IDL.Service({
'add_user_secret' : IDL.Func([Secret], [Result], []),
});
};
export const init = ({ IDL }) => { return []; };
declarations/index.d.ts
and index.js
are untouched and remain as generated.
In our ReactJS typescript code we try to call function add_user_secret()
in the following way:
import { HttpAgent } from "@dfinity/agent";
import { AuthClient } from "@dfinity/auth-client";
import { backend, createActor } from "../../../declarations/backend";
export async function add_secret () {
let xx = ???
let authClient = await AuthClient.create();
let identity = authClient.getIdentity();
let actor = iccrypt_backend;
const agent = new HttpAgent({ identity });
actor = createActor(process.env.ICCRYPT_BACKEND_CANISTER_ID, {
agent,
});
await actor.add_user_secret(xx);
}
…where xx obviously should be of type Secret
as defined in the declarations.
Any idea how to create the secret parameter to call the IC backend function is appreciated!
Thank you