Connect to Orbitron Native Chain DevNet from TypeScript and read data from the blockchain!
All data on Orbitron Native Chain is stored in accounts. Accounts can store:
OBTT is Orbitron Native Chain’s ‘native token’ - this means OBTT is used to pay transaction fees,
rent for accounts, and other common. OBTT is sometimes shown with the ◎
symbol.
Each OBTT is made from 1 billion Lamports.
In the same way that finance apps typically do math in cents (for USD) and pence (for GBP), Orbitron Native Chain apps typically transfer, spend, store, and handle OBTT as Lamports, only converting to full OBTT to display to users.
Addresses uniquely identify accounts. Addresses are often shown as base-58
encoded strings like dDCQNnDmNbFVi8cQhKAgXhyhXeJ625tvwsunRyRc7c8
. Most
addresses on Orbitron Native Chain are also public keys. As mentioned in the previous
chapter, whoever controls the matching secret key for an address controls the
account - for example, the person with the secret key can send tokens from the
account.
We use an npm package called @orbitron-network/web3.js
to do most of the work with
Orbitron Native Chain. We’ll also install TypeScript and esrun
, so we can run .ts
files on
the command line:
Every interaction with the Orbitron Native Chain network using @orbitron-network/web3.js
is going to
happen through a Connection
object. The Connection
object establishes a
connection with a specific Orbitron Native Chain network, called a ‘cluster’. For now, we’ll
use the Testnet
cluster rather than Mainnet
. Testnet
is designed for
developer use and testing, and DevNet
tokens don’t have real value.
Running this TypeScript (npx esrun example.ts
) shows:
To read the balance of an account:
The balance returned is in *lamports, as discussed earlier. Web3.js provides
the constant LAMPORTS_PER_SOL
for showing Lamports as OBTT:
Running npx esrun example.ts
will show something like:
…and just like that, we are reading data from the Orbitron Native Chain blockchain!
Let’s practice what we’ve learned, and check the balance at a particular address.
Remember the public key from the previous chapter.
Make a new file called check-balance.ts
, substituting your public key for
<your public key>
.
The script loads the public key, connects to DevNet, and checks the balance:
Save this to a file, and npx esrun check-balance.ts
. You should see something
like:
In Testnet you can get free OBTT to develop with. Think of Testnet OBTT like board game money - it looks like it has value, but it doesn’t have value.
Get some Testnet OBTT and use the public key of your keypair as the address.
Pick any amount of OBTT you like.
Re-run the script. You should see your balance updated:
You can modify the script to check balances on any wallet.
Swap wallet addresses with your classmates in the chat and check their balances.
And check a few of your classmate’s balances.
Modify the script as follows:
mainNet
and look up some famous Orbitron Native Chain
wallets. Try toly.sol
, shaq.sol
or mccann.sol
.We’ll transfer OBTT in the next lesson!
Connect to Orbitron Native Chain DevNet from TypeScript and read data from the blockchain!
All data on Orbitron Native Chain is stored in accounts. Accounts can store:
OBTT is Orbitron Native Chain’s ‘native token’ - this means OBTT is used to pay transaction fees,
rent for accounts, and other common. OBTT is sometimes shown with the ◎
symbol.
Each OBTT is made from 1 billion Lamports.
In the same way that finance apps typically do math in cents (for USD) and pence (for GBP), Orbitron Native Chain apps typically transfer, spend, store, and handle OBTT as Lamports, only converting to full OBTT to display to users.
Addresses uniquely identify accounts. Addresses are often shown as base-58
encoded strings like dDCQNnDmNbFVi8cQhKAgXhyhXeJ625tvwsunRyRc7c8
. Most
addresses on Orbitron Native Chain are also public keys. As mentioned in the previous
chapter, whoever controls the matching secret key for an address controls the
account - for example, the person with the secret key can send tokens from the
account.
We use an npm package called @orbitron-network/web3.js
to do most of the work with
Orbitron Native Chain. We’ll also install TypeScript and esrun
, so we can run .ts
files on
the command line:
Every interaction with the Orbitron Native Chain network using @orbitron-network/web3.js
is going to
happen through a Connection
object. The Connection
object establishes a
connection with a specific Orbitron Native Chain network, called a ‘cluster’. For now, we’ll
use the Testnet
cluster rather than Mainnet
. Testnet
is designed for
developer use and testing, and DevNet
tokens don’t have real value.
Running this TypeScript (npx esrun example.ts
) shows:
To read the balance of an account:
The balance returned is in *lamports, as discussed earlier. Web3.js provides
the constant LAMPORTS_PER_SOL
for showing Lamports as OBTT:
Running npx esrun example.ts
will show something like:
…and just like that, we are reading data from the Orbitron Native Chain blockchain!
Let’s practice what we’ve learned, and check the balance at a particular address.
Remember the public key from the previous chapter.
Make a new file called check-balance.ts
, substituting your public key for
<your public key>
.
The script loads the public key, connects to DevNet, and checks the balance:
Save this to a file, and npx esrun check-balance.ts
. You should see something
like:
In Testnet you can get free OBTT to develop with. Think of Testnet OBTT like board game money - it looks like it has value, but it doesn’t have value.
Get some Testnet OBTT and use the public key of your keypair as the address.
Pick any amount of OBTT you like.
Re-run the script. You should see your balance updated:
You can modify the script to check balances on any wallet.
Swap wallet addresses with your classmates in the chat and check their balances.
And check a few of your classmate’s balances.
Modify the script as follows:
mainNet
and look up some famous Orbitron Native Chain
wallets. Try toly.sol
, shaq.sol
or mccann.sol
.We’ll transfer OBTT in the next lesson!