2

I am currently developing an app that will request users to transfer X amount of sol to my wallet address via Phantom wallet, But I faced an error while testing this, the error was that "This account may not be used to pay transaction fees" after some research I found out that a wallet which signed a smart contract (created PDA or Non-PDA data account) has transferred Its ownership to the smart contract and can't sign the transfer. but I was wondering how to avoid this kind of error which is possible for a user who doesn't know how the Solana ownership works to try to sign a transfer transaction with a wallet that the owner is not SystemProgram, So I wanted to be sure that my understanding of this ownership is correct and to know what is the best practice to prevent it.

NOTE: I don't have a smart contract to do the transfer I just use anchor's transfer approach with TS code.

1 Answer 1

1

I found out that a wallet which signed a smart contract (created PDA or Non-PDA data account) has transferred Its ownership to the smart contract and can't sign the transfer

Each account in Solana is owned by a program. Wallets are owned by the system program, token accounts are owned by the token program. The runtime grants the program write access to the account if its id matches the owner.

For the case of the System program, the runtime allows clients to transfer lamports and importantly assign account ownership, meaning changing the owner to a different program id. If an account is not owned by a program, the program is only permitted to read its data and credit the account.

If your program doesn't have a way to get the ownership of the account back. That account will be forever owned by the program (unless you upgrade the program).

but I was wondering how to avoid this kind of error which is possible for a user who doesn't know how the Solana ownership works to try to sign a transfer transaction with a wallet that the owner is not SystemProgram

This is why you have to be careful when changing ownership. Your program has to handle transfers and/or ownership otherwise that wallet is gonna be dead

2
  • Hi vicyyn, Thanks for the answer but when you said "importantly assign account ownership" do you mean I have to change account ownership? if so do you have any code samples? Secondly, I don't change account ownership in transfer because It's a simple TS code, But I expect to face a wallet Whose ownership is changed and has trouble with the transfer. Commented Jan 16, 2023 at 10:31
  • You don't have to change the ownership, but the System Program allows you to reassign ownership. Your program can do the same if there's a reassign ownership instruction implemented. Only the owner program can reassign ownership. If the wallet is not owned by the System Program. You can't transfer funds unless you have transfer funds implemented for that program.
    – vicyyn
    Commented Jan 16, 2023 at 12:38

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.