How to close the main account and redeem the small amount (around 0.15$) that cannot be sent or used
How to close the main account and redeem the small amount (around 0.15$) that cannot be sent or used
Loading saved threads...
ascii bene · External communityPost link
External question — Solana Stack Exchange
Author: ascii bene
Original post: https://solana.stackexchange.com/questions/22991
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
I'm not very familiar with Solana technology but I have a few wallets on different platforms and I have noticed that on all of them there is always a small amount (roughly 0.001 SOL or 0.15$ in my currency) that remains in the wallet. it seems that I cannot send or swap it no matter what I do. Is there a way to close the account and get those small leftovers in any way?
I am not talking about closing token accounts (I'm well aware of the rent thing for tokens accounts) I am talking about the main account that is holding SOL. Everywhere I look online I cannot for the life of me find any info about that so I am very confused. A solution using CLI would be preferred but if it is absolutely necessary I can manage to do some coding to achieve this goal.
The reason for my asking is because I have a handful of those wallets who all hold 10 cents or so in SOL and I'd like to be able to get the 10 cents from all of them and if needed close the account because I won't be needing them anyways.
thank you for you help
Quote
Report
abelmarnk · External communityPost link
External answer — Solana Stack Exchange
Author: abelmarnk
Original post: https://solana.stackexchange.com/a/23012
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
Here is the script:-
import {
createKeyPairSignerFromBytes,
sendAndConfirmTransactionFactory,
createSolanaRpcSubscriptions,
createSolanaRpc,
pipe,
createTransactionMessage,
setTransactionMessageFeePayer,
setTransactionMessageLifetimeUsingBlockhash,
appendTransactionMessageInstructions,
signTransactionMessageWithSigners,
isSolanaError,
SOLANA_ERROR__JSON_RPC__SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE,
addSignersToTransactionMessage,
} from "@solana/kit";
import {
getSystemErrorMessage,
getTransferSolInstruction,
isSystemError
} from "@solana-program/system";
import bs58 from "bs58";
// Declare the private keys involved, e.g fee payer and the source accounts
const payerAndDestination = await createKeyPairSignerFromBytes(
bs58.decode("PayerAndDestinationKey"));
const sourceOfLamports = [
await createKeyPairSignerFromBytes(
bs58.decode("SourceKey1")),
await createKeyPairSignerFromBytes(
bs58.decode("SourceKey2")),
await createKeyPairSignerFromBytes(
bs58.decode("SourceKey3")),
// Add the keys for the other accounts here similarly to the above
];
const rpc = createSolanaRpc("https://api.mainnet-beta.solana.com");
const rpcSubscriptions = createSolanaRpcSubscriptions("wss://api.mainnet-beta.solana.com");
const sendAndConfirmTransaction = sendAndConfirmTransactionFactory({
rpc,
rpcSubscriptions,
});
// Get the blockhash
const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();
// Construct the instructions
const instructions = await Promise.all(sourceOfLamports.map( async (source)=>{
// Get the exact balance.
const lamportBalance = await rpc.getBalance(source.address).send();
return getTransferSolInstruction({
amount: lamportBalance.value,
destination: payerAndDestination.address,
source: source,
})}));
// Construct the transaction
const transactionMessage = pipe(
(createTransactionMessage({ version: 0 })),
tx => (
setTransactionMessageFeePayer(payerAndDestination.address, tx)
),
tx => (
setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx)
),
tx =>
appendTransactionMessageInstructions(
instructions,
tx,
),
tx => addSignersToTransactionMessage(
[payerAndDestination, ...sourceOfLamports],
tx
));
// Sign the transaction
const signedTransaction = await signTransactionMessageWithSigners(transactionMessage);
console.log("Transaction sinature: ", signedTransaction);
// Send it off
try {
await sendAndConfirmTransaction(signedTransaction, { commitment: 'confirmed' });
console.log("Transaction confirmed.");
} catch (e) {
if (isSolanaError(e, SOLANA_ERROR__JSON_RPC__SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE)) {
const preflightErrorMessage = e.message;
const errorDetailMessage = isSystemError(e.cause, transactionMessage)
? getSystemErrorMessage(e.cause.context.code)
: e.cause?.message;
console.log("preflightErrorMessage: ", preflightErrorMessage)
console.log("errorDetailMessage: ", errorDetailMessage)
} else {
throw e;
}
}
You would need to:-
Create a TS project
Install the modules used in the file
Add your keys(the fee payer paying for the transaction should be separate, the funds from the different addresses would go to it, and it should have enough to cover the transaction fees)
Run the script
After running the script you should empty the file of your keys.
Quote
Report
Post Reply
Quoted from Forex.com.bd-Editorial External question — Solana Stack Exchange Author: ascii bene Source score (net votes, not local likes): 0 Original post: https://solana.stackexchange.com/questions/22991 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I'm not very familiar with Solana technology but I have a few wallets on different platforms and I have noticed that on all of them there is always a small amount (roughly 0.001 SOL or 0.15$ in my currency) that remains in the wallet. it seems that I cannot send or swap it no matter what I do. Is there a way to close the account and get those small leftovers in any way? I am not talking about closing token accounts (I'm well aware of the rent thing for tokens accounts) I am talking about the main account that is holding SOL. Everywhere I look online I cannot for the life of me find any info about that so I am very confused. A solution using CLI would be preferred but if it is absolutely necessary I can manage to do some coding to achieve this goal. The reason for my asking is because I have a handful of those wallets who all hold 10 cents or so in SOL and I'd like to be able to get the 10 cents from all of them and if needed close the account because I won't be needing them anyways. thank you for you help
Checking account access…