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 new program account. Both the funding account and new account must sign the transaction.

def create_account(
from_public_key: PublicKey,
new_account_public_key: PublicKey,
lamports: int,
space: int,
program_id: PublicKey
) -> Instruction
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 new program account at an address derived from a base public key and seed string.

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
) -> Instruction
copy

Note: If base_public_key is different from from_public_key, the base public key must also sign the transaction.

allocate

Allocates space in an account without transferring lamports.

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 space in an account at an address derived from a base public key and seed string.

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

assign

Assigns an account to a program.

def assign(
account_public_key: PublicKey,
program_id: PublicKey
) -> Instruction
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. The sender must sign the transaction.

def transfer(
from_public_key: PublicKey | str,
to_public_key: PublicKey | str,
lamports: int
) -> Instruction
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