Issues with requestTransfer method using Plug Wallet: Insufficient funds and invalid service definition errors

Hello everyone,

I’m currently developing a Dapp using the Plug wallet and encountering a few issues with the requestTransfer method. I’ve been testing this locally, making sure that the host is set to my local network and that there is a positive balance in my wallet on the local ledger. Despite this, when I request a transfer, it errors with “insufficient funds” most of the time, and occasionally, I get an “invalid service definition” error.

Here is the code snippet I’m using:

const transferICP = async (toAccount, amountE8s) => {
    console.log("Connected network:", await window.ic.plug.agent);

    try {
        console.log("Transferring ICP to:", toAccount, "Amount:", amountE8s);
        const params = {
            to: toAccount,
            amount: amountE8s,
        };
        const transferResult = await window.ic.plug.requestTransfer(params);
        console.log("Transfer successful:", transferResult);
        return transferResult;
    } catch (error) {
        console.error("Error during ICP transfer:", error);
        throw error;
    }
};

Transferring through the Plug plugin directly to the destination account works without issue. I’ve also double-checked that the e8s amount I’m passing is correct and that the host is set to my local network. Does anyone know if there are any known bugs with this method, or is there something I might be missing in my setup?

Any insights or similar experiences would be greatly appreciated!

Thank you!

To clarify the toAccount variable i am passing here is the account number of my backend canister.

Hi @tuan.

Just to be sure, does the ledger canister ID on the configured local network also match the local ledger canister Id?

Hi @mzibara, yes i believe it does I have set it to be “ryjl3-tyaaa-aaaaa-aaaba-cai”.

I set the host here:

import { canisterId } from '../../../declarations/app_backend';

if (window.ic && window.ic.plug) {
    try {
        const nnsCanisterId = 'ryjl3-tyaaa-aaaaa-aaaba-cai';

        await window.ic.plug.requestConnect({
            whitelist: [canisterId, nnsCanisterId],
            host: "http://127.0.0.1:4943/"
        });
        const isConnected = await window.ic.plug.isConnected();
        if (isConnected) {
          const principal = await window.ic.plug.agent.getPrincipal();
          console.log('Principal:', principal);
        }
    } catch (error) {
        console.error('Error connecting to Plug:', error);
    }
}

I followed this post and didnt change anything related to the ledger canister id.

We still cannot integrate your wallet, its very frustrating for us.

We now have the following problem

Were encountering an issue with the chrome plugin where for some reason the requestbalance function was seemingly removed from window after the v2 release

@mzibara please advise what we can do!