I'm writing some unit tests and want to test that a user cannot update data on a PDA created by another user. How can I get "another user?" I'm creating the first user:

const provider = anchor.AnchorProvider.env()


await program.methods
          user: provider.wallet.publicKey,

Then I want to call updatePda with another wallet like so:

await program.methods
        .updatePda('NEW DATA')
          user: another_provider.another_wallet.publicKey,

Is this doable in anchor? Do I need a new wallet on the same provider, or do I need an entirely new provider?

1 Answer 1


Another user in your case is any Keypair

You can generate another Keypair using:

const user1 = anchor.web3.Keypair.generate();
const user2 = anchor.web3.Keypair.generate();

Then you can call updatePda with user1.publicKey

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.