Hi I'm studying this often cited custom token escrow program on Anchor in order to create something like it with a frontend. My question is about the creation of the EscrowAccount. (Account that holds the information of the escrow/exchange of coins.)

pub escrow_account: Box<Account<'info, EscrowAccount>>,
pub struct EscrowAccount {
    pub initializer_key: Pubkey,
    pub initializer_deposit_token_account: Pubkey,
    pub initializer_receive_token_account: Pubkey,
    pub initializer_amount: u64,
    pub taker_amount: u64,

I was wondering why they send a createInstruction in the typescript testfile instead of just initializing the account with init? What is the benefit?

 await program.rpc.initialize(
  new anchor.BN(initializerAmount),
  new anchor.BN(takerAmount),
    accounts: {
      initializer: initializerMainAccount.publicKey,
      vaultAccount: vault_account_pda,
      mint: mintA.publicKey,
      initializerDepositTokenAccount: initializerTokenAccountA,
      initializerReceiveTokenAccount: initializerTokenAccountB,
      escrowAccount: escrowAccount.publicKey,
      systemProgram: anchor.web3.SystemProgram.programId,
      rent: anchor.web3.SYSVAR_RENT_PUBKEY,
      tokenProgram: TOKEN_PROGRAM_ID,
    instructions: [
      await program.account.escrowAccount.createInstruction(escrowAccount),
    signers: [escrowAccount, initializerMainAccount],

And if this is the way to go, how do you replicate sending an instruction within the program instruction with multiple signers from a client through phantom wallet? Can you just pass EscrowAccount as a signer after generating the address on the client? It seems to error when I try that.

Thanks in advance!

1 Answer 1


If you look closely here, you would notice that data is written to the escrow_account. A Solana smart contract(program) can only write data to an Account If the Solana program owns the Account. The createInstruction basically does an Instruction to create an Account that is owned by the current Solana program. Once this Account is owned by the current executing program, the initialize instruction can then write data to the Account.

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.