I transfer the SOL/Lamports to the PDA accounts but I am not able to withdraw SOL from PDA back.
Transfer SOL to PDA
I generate PDA account from the below given code.
const GREETING_SEED = 'Hello';
greetedPubkey = await PublicKey.createWithSeed(
payer.publicKey,
GREETING_SEED,
programId,
);
const transaction = new Transaction().add(
SystemProgram.createAccountWithSeed({
fromPubkey: payer.publicKey,
basePubkey: payer.publicKey,
seed: GREETING_SEED,
newAccountPubkey: greetedPubkey,
lamports,
space: GREETING_SIZE,
programId,
}),
);
await sendAndConfirmTransaction(connection, transaction, [payer]);
Transaction of Sol make using below code snippet:
transaction.add(
SystemProgram.transfer({
fromPubkey:toaccount.publicKey,
toPubkey: greetedPubkey,
lamports: LAMPORTS_PER_SOL/100,
programId: programId,
}),
);
const signature=await sendAndConfirmTransaction(connection, transaction, [toaccount]);
Above code is working fine.
Withdraw SOL from PDA
But I am not able to withdraw SOL from the PDA account.
transaction.add(
SystemProgram.transfer({
fromPubkey: greetedPubKey,
toPubkey: toaccount.publicKey,
lamports: LAMPORTS_PER_SOL/100,
programId: programId,
}),
);
const signature=await sendAndConfirmTransaction(connection, transaction, [greetedPubKey]);
I try all the way to do it. But not able to sign transaction using PDA address. Is there any other way or Point if I make any mistake