3
  1. What is the difference between provider.wallet.Pubkey , provider.Pubkey and anchor.web3.Keypair.generate().publicKey at testing? I am confused where to use each one of them because they look the same .

My rust code :

#[derive(Accounts)]
pub struct SignUp<'info> {

#[account(init,
          payer = authority, 
          space = size_of::<UserAccount>() + USER_NAME_LENGTH + EMAIL_LENGTH + NAME_LENGTH + PHONE_NUMBER_LENGTH + 8 + 8 + 2 + 2 )]
pub user: Account<'info, UserAccount>,

// Associated user with the smart contract who paid transaction fee 
#[account(mut)]
pub authority: Signer<'info>,

// It's the smart contract that we have 
pub system_program: Program<'info , System>,


pub clock: Sysvar<'info , Clock>
}

And my test:

        await program.methods.signUp("reasje", "09146979106", "").accounts({
        user: user.publicKey,
        authority: provider.wallet.publicKey,
        systemProgram: SystemProgram.programId,
        clock: anchor.web3.SYSVAR_CLOCK_PUBKEY,
    }).signers([user]).rpc({ skipPreflight: true });
  1. Why the authority (Signer) should be provider.wallet.publickey (Others give Error: Raw transaction 2L8Zk5tBUhz57dDBAKVGW6JXkFZhSb1mX8izMnm5dBjFaBvznji6S9AEpFTtJh4C6NHBGCtjuVgKN1yJ6VWytTwL failed ({"err":{"InstructionError":[0,"InvalidArgument"]}}) error), but the account is being created with user wallet.

  2. What is the point of using .signers([user]) ? (Which not using it gives ‍‍‍‍‍‍‍‍‍‍‍‍Error: Signature verification failed error), while i am signing the trx with the authority

  3. Why deleting the authority: from the test works fine too ?

1 Answer 1

3

What is the difference between provider.wallet.Pubkey , provider.Pubkey and anchor.web3.Keypair.generate().publicKey ...

A crypto wallet is a device or application that stores a collection of keys and can be used to send, receive, and track ownership of cryptocurrencies. Wallets can take many forms. A wallet might be a directory or file in your computer's file system, a piece of paper, or a specialized device called a hardware wallet. There are also various smartphone apps and computer programs that provide a user-friendly way to create and manage wallets.

A keypair is a securely generated private key and its cryptographically-derived public key. A private key and its corresponding public key are together known as a keypair. A wallet contains a collection of one or more keypairs and provides some means to interact with them.

Why the authority (Signer) should be provider.wallet.publickey

provider.wallet.publickey is always a signer (in anchor). Since you're using it to pay for transaction fees. In this case, you can use another publickey but it has to be a signer in your transaction by adding it to .signers([<signer>])

What is the point of using .signers([user]) ?

Besides the provider.wallet.publickey which is a signer by default in anchor tests. You can add other signers (like I mentioned before) by adding there to .signers([])

Here we need user as a signer because we are modifying that account (initializing). We don't need it as a signer if it's a PDA

Why deleting the authority: from the test works fine too?

provider.wallet.publickey is signer by default.

2
  • Thanks for the answer but for the first question your answer is unrelated, What i meant by that question is if they are all wallets what is the motivation to have three of them ? However with your answer it's clear now, but only provider.Pubkey's usage is unclear to me . Commented Aug 16, 2022 at 5:24
  • A wallet contains a collection of one or more keypairs and provides some means to interact with them.. I'm not sure about provider.Pubkey tho, never used it :))
    – vicyyn
    Commented Aug 16, 2022 at 7:26

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.