Seahorse is beta software. Many features are unimplemented and it's not production-ready.

GitHub

Using Seahorse

Accounts

Account (Base type)

By deriving from the base Account type, you can make your own program accounts.

Usage:

class MyAccount(Account):
  data: u64
  
@instruction
def use_my_account(my_account: MyAccount):
  # Gets the pubkey from this account.
  key = my_account.key()
  # Sets the value of `data` in this account.
  my_account.data = 1

Right now, accounts (and other classes in Seahorse) can only define their underlying data type by using type-annotated fields with no default value. You're also allowed to define arbitrary classes and enums to use in your accounts, like so:

class MyAccount(Account):
  enum: MyEnum
  data: MyData


class MyEnum(Enum):
  # Enums are the only place where you need to use this syntax, which should be
  # familiar if you've used Python enums before. The numbers don't actually do
  # anything here, they're just there for parsing.
  OPTION_ONE = 1
  OPTION_TWO = 2
  OPTION_N = 3


class MyData:
  field1: u8
  field2: u64

Built-in account types

Signer

Wallet that signed the transaction with this instruction call. Often used as an account payer or seed.

Usage:

@instruction
def use_signer(signer: Signer):
  # Gets the pubkey of the signer (as a Pubkey type).
  key = signer.key()

Empty

Account that will be initialized by this instruction.

Usage:

@instruction
def use_empty(empty: Empty[MyAccount], signer: Signer):
  # Initializes the empty account. `signer` will pay for the cost of creating
  # the account (rent).
  # Because the seeds uniquely identify this account among all other accounts
  # created by this program, if the same signer calls this instruction again,
  # it will fail due to trying to re-initialize an existing Solana account.
  my_account = empty.init(
    payer = signer,
    seeds = ['MyAccount', signer]
  )
Previous
Calculator: Your first Seahorse program