0

While I have a main account A and has its keypair. Then I use createWithSeed create one account derived account x, and asign it to one program C. Now the problem is : I want to change the account x's owner, I want to change it to another program D.

Most important : I want to do this by my own client code like this.

const transaction = new web3.Transaction().add(
      web3.SystemProgram.assign({
        accountPubkey: ada_account,
        basePubkey: signer.publicKey,
        programId: new web3.PublicKey(
          "HwFF1oi1uD14nRbDkrtrjsJqzs45WkQ9eP8YakAxG3PG"
        ),
        seed,
      })
    );

    let signature = await web3.sendAndConfirmTransaction(
      connection,
      transaction,
      [signer]
    );
    console.log(signature);

Then it comes out error :

 logs: [
    'Program 11111111111111111111111111111111 invoke [1]',
    'Create: address FCJi4ZXsLdReyQB4zhLd6GqFH9w81Dm7ktXHJ7Nve3Z9 does not match derived address 5NScAVTG1uPp87Rq7WuFyYGbExW4hvhrQX9iYH2UUyCD',
    'Program 11111111111111111111111111111111 failed: custom program error: 0x5'
  ]
}

1 Answer 1

1

Once an account is assigned to a program C, the only way to re-assign it is through an instruction in program C.

For example, the token program assigns accounts back to the system program when an account is closed using account_info.assign(system_program::id()) at https://github.com/solana-labs/solana-program-library/blob/7b6119895e167d4672a87cca4895c7802ca92c99/token/program/src/processor.rs#L1025

system_instruction::assign only works on accounts that are owned by the system program. So you need to implement an instruction in C to reassign.

2
  • Thanks. I think that's the right answer about it. Ony the owner program can change the data or the account even it's system program.
    – xingyue
    Commented Sep 4, 2023 at 8:57
  • Please accept the answer if you think it's right, so that others may find it more easily in the future
    – Jon C
    Commented Sep 13, 2023 at 11:40

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.