Rust is the Language, Solana uses to build Programs / Accounts (Smart Contracts)
To store Data on Solana, an Account must be created each Time
These Accounts store Data in the Blockchain therefore it is possible to:
Programs create, retrieve, update or delete Accounts, but they need Accounts to store Information as it can not be stored in the Program
Programs are special Accounts that:
There is an Executable Boolean on every single Account that indicates if this Account is a Program or a regular Account that stores Data
Rent is a Concept in Solana that ensures everybody that adds Data to the Blockchain is accountable for the Amount of Storage they provide
The Rent Concept works as follows:
A Lamport is the smallest Decimal of Solana's native Token SOL
If enough Lamport (SOL) is added in the Account to pay the Equivalent of two Years of Rent the Account become rent-exempt
Once done this, the Lamport (Sol) will stay on the Account forever and will never be collected
If the Account is closed its Lamport (SOL) will be refunded to the Owner
Solana Defaults to allocating twice the Amount of Space needed to store the Program because the Program is likely to have Updates in the Future
Solana Commitment describes how finalized a Block is at the Point of Sending the Transaction:
When Sending a Transaction to the Blockchain it is added to a Block which will need to be finalized before officially becoming a Part of the Blockchain’s Data
Therefore, there are the following three Commitment Levels:
commitment
and preflightCommitment
both of them define the Level of Commitment that is expected from the Blockchain when sending a Transaction
preflightCommitment
will be used when Simulating a Transaction whereas commitment
will be used when Sending the Transaction on the Mainnet
Every Tweet is stored on its own Account
That Way, Storage will be created and paid on Demand by the Author of the Tweet
Since each Tweet will require only a small Amount of Space, the Storage will be more affordable and will scale to an unlimited Amount of Tweets and Users
Granularity pays in Solana
The Owner of an Account will be the Program that generated it, therefore the Field author
in a Tweet is necessary:
The Solana-Twitter Program is owned by another Account which is Solana's System Program
This executable Account also owns every User an Account
The System Program is ultimately the ancestor of all Solana Accounts
tweet
: This is the Account that the Instruction will create by passing the Public Key that should be used when Creating the Account and also its Private Key to prove that the Instruction owns the Public Keyauthor
: This Account is used to know who is Sending the Tweet, and also to get the Signature of the Sender to prove itsystem_program
: This is the official System Program (Account) from Solana that will pass through to interact with the stateless Programs. It will initialize the Tweet Account and figure out how much Lamport (SOL) is necessary for it to be rent-exempt@solana/web3.js
that encapsulates this API by providing a Bunch of asynchronous MethodsConnection
Object that requires a Cluster for it to know where to send its RequestsWallet
Object that has Access to the Key Pair of the User who makes the Transaction is necessary to sign them and prove his Identity@project-serum/anchor
that provides a Wallet
Object that requires a Key Pair and allows signing Transactions@project-serum/anchor
also provides a Provider
Object that wraps both the Connection
and the Wallet
and automatically adds the Wallet’s Signature to outgoing TransactionsIDL
(Interface Description Language)IDL
File contains a structured Description of the Solana Program including its Public Key, Instructions and AccountsProgram
uses both the IDL
and the Provider
to create a Custom JavaScript API that completely matches the Solana ProgramProgram
Object can interact with the Solana Program on Behalf of a Wallet without even needing to know anything about the underlying API
dataSize
Filter that takes a Size in Bytes, and it will only return Accounts that match exactly that Size{ dataSize: 2000 }
will not include Accounts above or below 2000 Bytes in the Resultmemcmp
Filter allows comparing an Array of Bytes with the Account's Data at a particular Offsetmemcmp
Filter takes an Array of Bytes that should be present in the Account's Data at a certain Position, and it will only return these Accounts{ memcmp: { offset: 42, bytes: 'D4AFE..' } }
will include all Accounts that have the given Public Key at the 42nd ByteType | Size |
---|---|
bool | 1 Byte |
u8 or i8 | 1 Byte |
u16 or i16 | 2 Byte |
u32 or i32 | 4 Byte |
u64 or i64 | 8 Byte |
u128 or i128 | 16 Byte |
[u16; 32] | 64 Byte |
PubKey or [u8; 32] | 32 Byte |
vec |
Any Multiple of 2 Byte + 4 Bytes for the Prefix |
String or vec<8> | Any Multiple of 1 Byte + 4 Bytes for the Prefix |
programs
Folder contains all our Solana Programstests
Folder contains all JavaScript Tests that directly interact with the ProgramsAnchor.toml
Configuration File helps to configure the Program ID, Solana Clusters, Test Command, etc.app
Folder contains the JavaScript ClientCommand | Description |
---|---|
anchor build | Compiles and builds the Program and generate the IDL |
anchor deploy | Deploys the compiled Program (Build) on the Cluster and it will also generate a Public and Private Key for it |
anchor run script | Runs a given Script from the Anchor.toml Configuration File |
anchor test | Starts a local Ledger that will be automatically terminated at the End of all Tests and build, deploy and test the Program |
anchor idl init |
Publishes the IDL File to allow other Tools in the Solana Ecosystem to interact with the Program |
anchor idl upgrade |
Upgrades the IDL File to allow other Tools in the Solana Ecosystem to interact with the Program |
Command | Description |
---|---|
solana-test-validator --reset | Runs a Simulation of a Solana Cluster inside the local Machine and terminate it after the Command |
solana address -k target/deploy/solana_twitter-keypair.json | Returns the Public Key of the Program that was generated when the Program was deployed |