Instructions

A transaction requires you to have instructions which it will execute. The following functions are the available instructions which you can use.

Import syntax

from solathon.core.instructions import *

Instruction functions

Classes

Instructions

create_account

Creates a program account. When sending the transaction, both existing account and new account keypairs need to be passed in the signers argument of the Transaction object.

def create_account(
from_public_key: PublicKey,
new_account_public_key: PublicKey,
lamports: int,
space: int,
program_id: PublicKey
)
copy

Example:

from solathon.core.instructions import create_account
from solathon import Client, Transaction, PublicKey, Keypair
ã…¤
client = Client("https://api.devnet.solana.com")
ã…¤
# Requires you to have some SOLs to pay for transaction fees
sender = Keypair.from_private_key("your_private_key")
new_account = Keypair()
program_id = PublicKey("11111111111111111111111111111111") # System program
ã…¤
instruction = create_account(
from_public_key=sender.public_key,
new_account_public_key=new_account.public_key,
lamports=100,
space=0,
program_id=program_id
)
transaction = Transaction(instructions=[instruction], signers=[sender, new_account])
ã…¤
result = client.send_transaction(transaction)
print("Transaction response: ", result)
copy

create_account_with_seed

Creates a program account using seed

def create_account_with_seed(
from_public_key: PublicKey,
new_account_public_key: PublicKey,
base_public_key: PublicKey,
seed: str,
lamports: int,
space: int,
program_id: PublicKey
)
copy

allocate

Allocates bytes for an account, this can only be used once for an account without any space already.

def allocate(
account_public_key: PublicKey,
space: int
)
copy

Example:

from solathon.core.instructions import allocate
from solathon import Client, Transaction, PublicKey, Keypair
client = Client("https://api.devnet.solana.com")
# Requires you to have some SOLs to pay for transaction fees
account = Keypair.from_private_key("your_private_key")
instruction = allocate(
account_public_key=account.public_key,
space=100
)
transaction = Transaction(instructions=[instruction], signers=[account])
result = client.send_transaction(transaction)
print("Transaction response: ", result)
copy

allocate_with_seed

Allocates bytes for an account with seed.

def allocate_with_seed(
account_public_key: PublicKey,
base_public_key: PublicKey,
seed: str,
space: int,
program_id: PublicKey
)
copy

assign

Assigns an existing account to a program.

def assign(
account_public_key: PublicKey,
program_id: PublicKey
)
copy

Example:

from solathon.core.instructions import assign
from solathon import Client, Transaction, PublicKey, Keypair
client = Client("https://api.devnet.solana.com")
# Requires you to have some SOLs to pay for transaction fees
account = Keypair.from_private_key("your_private_key")
program_id = PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA") # Token program
instruction = assign(
account_public_key=account.public_key,
program_id=program_id
)
transaction = Transaction(instructions=[instruction], signers=[account])
result = client.send_transaction(transaction)
print("Transaction response: ", result)
copy

transfer

Transfers lamports between accounts

def transfer(
from_public_key: PublicKey | str,
to_public_key: PublicKey | str,
lamports: int
)
copy

Example:

from solathon.core.instructions import transfer
from solathon import Client, Transaction, PublicKey, Keypair
client = Client("https://api.devnet.solana.com")
# Requires you to have some SOLs to pay for transaction fees
sender = Keypair.from_private_key("your_private_key")
receiver = PublicKey("receiver_public_key")
instruction = transfer(
from_public_key=sender.public_key,
to_public_key=receiver,
lamports=100
)
transaction = Transaction(instructions=[instruction], signers=[sender])
result = client.send_transaction(transaction)
print("Transaction response: ", result)
copy

Classes

AccountMeta

This is a dataclass representing meta-data of an account

@dataclass
class AccountMeta:
public_key: PublicKey | str
is_signer: bool
is_writable: bool
copy

Instruction

This is a named tuple representing an instruction object. Here keys are AccountMeta dataclass, program_id is the PublicKey of the program and data is our compiled instruction in bytes.

class Instruction(NamedTuple):
keys: list[AccountMeta]
program_id: PublicKey
data: bytes = bytes(0)
copy