0

everyone, I have a question about signers.

In https://www.rareskills.io/post/anchor-signer(No need to view), The Signerof the contract and the.signers([newKeypair])of ts are in one-to-one correspondence.

but in https://github.com/solana-developers/program-examples/blob/main/tokens/transfer-tokens/anchor/programs/transfer-tokens/src/instructions/create.rs, the main code is

#[derive(Accounts)]
pub struct CreateToken<'info> {
    #[account(mut)]
    pub payer: Signer<'info>,

    #[account(
        init,
        payer = payer,
        mint::decimals = 9,
        mint::authority = payer.key(),
        mint::freeze_authority = payer.key(),

    )]
    pub mint_account: Account<'info, Mint>,
}

we know payer: Signer<'info>, and mint_account: Account<'info, Mint>,

Why does ts call with.signers([mintKeypair])?

    const transactionSignature = await program.methods
      .createToken(metadata.name, metadata.symbol, metadata.uri)
      .accounts({
        payer: payer.publicKey,
        mintAccount: mintKeypair.publicKey,
      })
      .signers([mintKeypair])
      .rpc();

In https://github.com/solana-developers/program-examples/blob/main/tokens/transfer-tokens/anchor/tests/test.ts.

I think it must need the signature of pay, but it doesn't need pay.

1 Answer 1

0

All accounts on Solana, by default, belong to the System Program. When you create a mint account (or most other accounts), you need to assign it to another program. In your example, you're assigning the new mint account to the SPL Token program. This operation requires a signature from the mint account.

In your TS code, typically the program instance is configured with a keypair, which is used as the default payer for all transactions.

You can read more about the Solana account model at https://solana.com/docs/core/accounts

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.