Instructions
The @instruction decorator
Converting a function to an instruction is as simple as adding the @instruction
decorator.
The parameters of an instruction can include both accounts and regular parameters. On the Rust/Anchor side, accounts are separated and put into an accounts context struct.
Debug logging with print
You can write to Solana's program log with the builtin print
function:
Structured logging with Events
Seahorse also supports Anchor events, a structured method of logging subscribable information (via Anchor's TypeScript SDK). To use an event, create a class with Event
as its parent class:
When a class inherits from Event
, it gains the .emit()
function, which is used just like Anchor's emit!
to log the event:
Inferred program accounts
In Solana, programs are a special type of accounts. When writing a Solana program, you need to pass in every account that gets used - programs included. Seahorse simplifies this by inferring the necessity of certain program accounts, so that you don't have to include them in your instruction params.
The following table summarizes which programs Seahorse infers
Program | Needed when... |
---|---|
System program | Initializing accounts |
SPL Token program | Transferring SPL tokens |
Instructions are special - they are the only place where programs accounts can be inferred. This also means that you can't make certain calls from outside of an instruction (for example, Empty.init(...)
), otherwise the compiler won't be able to attach the inferred System program account to anything. For now this just becomes an error, a future update may make this more flexible.
Last updated