2

We can easily close PDAs to redeem their rent to their owner, however what I'm wondering is can the same be done for a normal, on-curve Solana account? From what I can see once you've sent the minimum rent-exempt balance to a new account, those funds are stuck there forever. Is there a way I can get those funds back out by closing the new account?

(I'm looking for a programmatic solution, preferably in Typescript)

2
  • You don't even need to send min rent exemption fee to normal account if you would like to use it as a signer only but you can use fee payer separately. Commented Jun 15, 2023 at 8:49
  • That's true, but I'm asking assuming I have sent the minimum amount already.
    – Ahri
    Commented Jun 16, 2023 at 9:23

3 Answers 3

3

For accounts owned by the system programs, which we normally call "wallets", you just need to system_instruction::transfer the funds out of it.

For accounts owned by other programs, there's no generic way to "close" them and recover the lamports. The program must expose a way to retrieve those lamports.

For example, the native stake program allows you to withdraw all of the lamports in a deactivated staked account, which closes it. On the other hand, the SPL token program exposes the close_account instruction.

All that to say, you need bindings into the program, and one of the instructions in the program must allow you to retrieve rent-exempt lamports. There is no general way to do this.

Side note: I think it would be a great general interface to add, so programs can all implement the same instruction, and that way you can close any account! Feel free to suggest an interface sRFC for close_account, similar to Anatoly's at https://forum.solana.com/t/srfc-00015-interfaces/267

0

In Anchor/Rust you simply set the account to "close" and specify where the rent will go:

    #[account(mut, close = rent_destination)]
    some_account: Account<'info>,

In TS you can't close a PDA, since only the program has authority to transfer those funds, but you can close a Token Account, for example, with createCloseAccountInstruction or closeAccount (from the spl-token library).

3
  • Thanks for your answer, but to be clear - I know how to close a PDA (including Token Accounts) already. I'm asking if there's a way to close an on-curve account.
    – Ahri
    Commented Jun 16, 2023 at 9:22
  • Who would be the owner in that scenario? Usually a program opens the account and owns it, so the program is also responsible for closing the account.
    – Whiteseal
    Commented Jun 19, 2023 at 21:21
  • I'm thinking more in an analog to how selfdestruct works over in Ethereum land - the account can call this on itself using a tx it signed and the SystemProgram (since that owns every account not owned by a different program) and specify a different account that should receive its rent
    – Ahri
    Commented Jun 20, 2023 at 6:30
0

Check this out this example of close account

https://yihau.github.io/solana-web3-demo/advanced/token/close-account.html

1
  • Thanks for your answer, but to be clear - I know how to close a PDA (including Token Accounts) already. I'm asking if there's a way to close an on-curve account.
    – Ahri
    Commented Jun 16, 2023 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.