-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
Trying to sign a tx like this to an Anchor ix that creates a Token account with init:
console.log(`globalAdmin balance: ${await banksClient.getBalance(globalAdmin.publicKey)}`);
// Prints "globalAdmin balance: 100000000000"
await program.methods
.initializeProgram(feeAddress.publicKey)
.accounts({
globalState: getGlobalStateAddress(program),
globalAdmin: globalAdmin.publicKey,
})
.signers([globalAdmin])
.rpc();
I'm getting:
"...Transfer: insufficient lamports 0, need 4823280...",
The account is being funded like this, where funder is provider.wallet.payer and receiver the globalAdmin account:
const ixs = [
anchor.web3.SystemProgram.transfer({
fromPubkey: funder.publicKey,
toPubkey: receiver,
lamports: BigInt(amount.toString()),
}),
];
const tx = new anchor.web3.Transaction();
[tx.recentBlockhash] = await banksClient.getLatestBlockhash();
tx.add(...ixs);
tx.sign(funder);
await banksClient.processTransaction(tx);
let balance;
let hash;
[balance, hash] = await Promise.all([banksClient.getBalance(receiver), banksClient.getLatestBlockhash()]);
// Ensure the balance is confirmed
while (balance === BigInt(0)) {
[balance, hash] = await Promise.all([banksClient.getBalance(receiver), banksClient.getLatestBlockhash()]);
await sleep(10);
}
Notice that I even await a little to ensure that the next block was reached (Sometimes I had a 0 lamports log when fetching the account balance if not).
However, in this other toy repo I made to inspect the bug I did not have the error 🤔
Metadata
Metadata
Assignees
Labels
No labels