gill vs @solana/kit
Explore a side-by-side comparison of gill and @solana/kit (formerly known as web3js v2)
The gill library is built directly on top of
@solana/kit
, the new JavaScript primitives developed
by Anza as a more performant replacement for the old
@solana/web3.js
. Since Kit only ships these new
low level primitives, developers are forced into a single experience of manually crafting everything
and ballooning their applications with verbose boilerplate.
Gill is able to ship both the same low level primitives as Kit and lightly opinionated abstractions to simplify common tasks, all from a single compatible interface. By simplifying across the board with gill, developers can focus more time on their application's business logic and not verbose boilerplate.
@solana/kit
was formerly know as "web3.js v2" as it was originally published as the version
2.x
release of @solana/web3.js
. Anza engineers noted this to complicate and confuse the
upgrade path for the new technologies, so they decided to publish under the new package name of
@solana/kit
.
You can find the complete scripts that the example code snippets were created from in the gill repo here. Both are written with honest intentions, best practices, and attempt to be as concise as possible in accomplishing the same task.
Connecting to the blockchain
Every application will need to create a connection to the blockchain. A complete and usable connection consists of the following three parts (at a minimum):
rpc
- used to send Solana RPC requests over HTTP (the most common way)rpcSubscriptions
- used to make certain RPC requests over websocketssendAndConfirmTransaction
- function used to actually send a complete transaction to the blockchain for confirmation
The following code snippets demonstrate how to instantiate all three of these connection pieces for each of the libraries:
Making RPC requests
For both @solana/kit
and gill
, making standard Solana RPC requests is the same: use the
previously created rpc
object.
Loading a signer
There are many different ways to obtain a keypair that is capable of performing the Solana specific signing operations (aka a "signer"). This will look different for frontend and backend applications.
For local scripts, JavaScript server runtimes (like NodeJS and Bun), and backend applications it's common to load a keypair from the file system or an ENV variable. The following is how to accomplish this for both libraries:
Note that @solana/kit
has no specific functionality for loading keypairs from files or ENV
variables, so developers must implement the file/ENV reading operations themselves.
Whereas gill includes multiple functions to handle these very scenarios:
loadKeypairSignerFromFile()
loadKeypairSignerFromEnvironment()
loadKeypairSignerFromEnvironmentBase58()
The loadKeypairSignerFromFile()
function defaults to the Solana CLI's keypair path
(~/.config/solana/id.json
). If you wish to load a different keypair file, provide the path in as
an argument.
Creating a transaction
After connecting to the blockchain and making RPC requests, the next most common tasks is actually creating transactions.
The following are examples of how to create a simple Memo transaction that includes basic optimizations (via compute budget instructions):
Notice that the @solana/kit
based example above requires manually installing two additional
packages: @solana-program/compute-budget
and @solana-program/memo
.
Whereas gill takes a different approach:
createTransaction
natively supports setting the same compute budget instructions- the included Memo program client is directly accessible via the
gill/programs
import path without having to manually install the package