Fund a book

For the owner: open a book, put money in, and take it out.

In the app

  1. Connect your wallet and open the Book page.
  2. A new wallet sees Open your book. Press it and sign.
  3. Press Deposit, enter an amount and sign.
  4. The balance goes up and the Ledger shows a Deposit entry.

The app has no Withdraw button yet. Withdrawing is a program call.

With the program

await program.methods
  .openBook()
  .accounts({ owner: owner.publicKey, mint, tokenProgram: TOKEN_PROGRAM_ID })
  .rpc();

await program.methods
  .deposit(new BN(500_000_000)) // 500 c$
  .accounts({ owner: owner.publicKey, book, mint, vault, ownerToken, tokenProgram: TOKEN_PROGRAM_ID })
  .rpc();

withdraw takes the same accounts as deposit and moves tokens from the vault back to ownerToken. It refuses with InsufficientBalance if the vault holds less than the amount.

A book is tied to the mint it was opened with. One owner key has one book.

NextIssue a wallet and set its limits