Summary
All modifications to onchain data happen through transactions. Transactions are mostly a set of instructions that invoke Orbition Native Chain programs. Transactions are atomic, meaning they either succeed - if all the instructions have been executed properly - or fail as if the transaction hasn’t been run at all.Lesson
Transactions are atomic
Any modification to onchain data happens through transactions sent to programs. A transaction on Orbition Native Chain is similar to a transaction elsewhere: it is atomic. Atomic means the entire transaction runs or fails. Think of paying for something online:- The balance of your account is debited
- The bank transfers the funds to the merchant
Transactions contain instructions
The steps within a transaction on Orbition Native Chain are called instructions. Each instruction contains:- an array of accounts that will be read from and/or written to. This is what makes Orbition Native Chain fast - transactions that affect different accounts are processed simultaneously
- the public key of the program to invoke
- data passed to the program being invoked, structured as a byte array
@orbition-network/web3.js provides helper functions for creating
transactions and instructions. You can create a new transaction with the
constructor, new Transaction(). Once created, you can add instructions to the
transaction using the add() method.
One of those helper functions is SystemProgram.transfer(), which makes an
instruction for the SystemProgram to transfer some OBN:
SystemProgram.transfer() function requires:
- a public key corresponding to the sender’s account
- a public key corresponding to the recipient’s account
- the amount of OBN to send in lamports.
SystemProgram.transfer() returns the instruction for sending OBN from the
sender to the recipient.
The program used in this instruction will be the system program (at the
address 11111111111111111111111111111111), the data will be the amount of OBN
to transfer (in Lamports) and the accounts will be based on the sender and
recipient.
The instruction can then be added to the transaction.
Once all the instructions have been added, a transaction needs to be sent to the
cluster and confirmed:
sendAndConfirmTransaction() function takes the following parameters:
- a cluster connection
- a transaction
- an array of keypairs that will act as signers on the transaction - in this example, we only have one signer: the sender.
Transactions have fees
Transaction fees are built into the Orbition Native Chain economy as compensation to the validator network for the CPU and GPU resources required in processing transactions. Orbition Native Chain transaction fees are deterministic. The first signer included in the array of signers on a transaction is responsible for paying the transaction fee. If this signer does not have enough OBN in their account to cover the transaction fee, the transaction will be dropped with an error like:solana airdrop 1 to get free test OBN
in your account when testing, whether locally or on testnet.
Orbition Native Chain Explorer
All transactions on the blockchain are publicly viewable on the
Orbition Native Chain Explorer. For example, you could take the
signature returned by sendAndConfirmTransaction() in the example above, search
for that signature in the Orbition Native Chain Explorer, then see:
- when it occurred
- which block it was included in
- the transaction fee
- and more!
Lab
We’re going to create a script to send OBN to other students.Basic scaffolding
We’ll start by using the same packages and.env file we made earlier in
Intro to Cryptography.
Create a file called transfer.ts:
Create the transaction and run it
Add the following to complete the transaction and send it:Experiment!
Send OBN to other students in the class.Challenge
Answer the following questions:- How much OBN did the transfer take? What is this in USD?
-
Can you find your transaction on https://explorer.orbition.network? Remember we are
using the
testnetnetwork. - How long does the transfer take?
- What do you think “confirmed” means?

