if (dto.alreadyEntered) {
const result = await identityActor.submitEuro2024Prediction(dto);
console.log(result);
if (isError(result)) {
console.error("Error saving Euro2024 prediction.");
return;
}
return result;
}
authStore.subscribe(async (auth) => {
const agent = await createAgent({
identity: auth.identity!,
host: process.env.DFX_NETWORK === "ic"
? `https://${ActorFactory.getAgent()}.icp-api.io`
: `http://localhost:8080/?canisterId=qhbym-qaaaa-aaaaa-aaafq-cai`,
fetchRootKey: true
});
const { transfer } = IcrcLedgerCanister.create({
agent,
canisterId: Principal.fromText("avqkn-guaaa-aaaaa-qaaea-cai")
});
let principal = auth.identity?.getPrincipal();
if(principal){
let subaccount: Uint8Array = principalToSubAccount(principal);
console.log(subaccount)
let transfer_result = await transfer({
to: {
owner: Principal.fromText(
process.env.FOOTBALL_GOD_BACKEND_CANISTER_ID ?? "",
),
subaccount: [subaccount],
},
fee: 100_000n,
memo: new Uint8Array(Text.encodeValue("0")),
from_subaccount: undefined,
created_at_time: BigInt(Date.now()),
amount: 100_000_000_000n,
});
console.log(transfer_result);
}
Thinking the problem might be the undefined from_subaccount but I transferred from my local nns to that sub account using just my apps principal id. So maybe the from_subaccount needs to be a combination of (FPL_SNS_LEDGER_CANISTER, CALLER). If so, how do I create this blob from these 2 principals…
If i get you correctly you want the caller to make the transfer right?
to do that you should be passing the prinicpalId as the owner not the canisterId
something like this
let principal = auth.identity?.getPrincipal();
if(principal){
let subaccount: Uint8Array = principalToSubAccount(principal);
console.log(subaccount)
let transfer_result = await transfer({
to: {
owner: Principal.fromText(principal), //take note of this line
subaccount: [subaccount],
},
fee: 100_000n,
memo: new Uint8Array(Text.encodeValue("0")),
from_subaccount: undefined,
created_at_time: BigInt(Date.now()),
amount: 100_000_000_000n,
});
console.log(transfer_result);
with this, the caller is recognized as the one doing the transfer
Well that’s the ‘to’ field. I want to transfer ‘to’ my app, whose principal is the football_god_backend and I want to mark it as the users by using the caller as the sub account.
Before rushing to change the code, did you actually had a look to the all error?
“Failed to transfer” is just the message, the error returned by transfer() provides more information, namely an errorType. Having a further look to it should provide more information about the effective issue.
Well, that was just a snippet to explain, I excepted you to finalize the proper code. You can cast it as any for quick debug or the actual type is IcrcTransferError.
Yeah the whole time it’s been wrapped in a try catch with a log for the error but it doesn’t ever get there. Just doing this returns me to my original error: