Web3 API Reference
#
Web3 API Reference GuideThe @solana/web3.js
library is a package that has coverage over the Solana JSON RPC API.
You can find the full documentation for the @solana/web3.js
library here.
#
General#
ConnectionConnection is used to interact with the Renec JSON RPC. You can use Connection to confirm transactions, get account info, and more.
You create a connection by defining the JSON RPC cluster endpoint and the desired commitment. Once this is complete, you can use this connection object to interact with any of the Renec JSON RPC API.
#
Example UsageThe above example shows only a few of the methods on Connection. Please see the source generated docs for the full list.
#
TransactionA transaction is used to interact with programs on the Renec blockchain. These transactions are constructed with TransactionInstructions, containing all the accounts possible to interact with, as well as any needed data or program addresses. Each TransactionInstruction consists of keys, data, and a programId. You can do multiple instructions in a single transaction, interacting with multiple programs at once.
#
Example Usage#
KeypairThe keypair is used to create an account with a public key and secret key within Renec. You can either generate, generate from a seed, or create from a secret key.
#
Example UsageUsing generate
generates a random Keypair for use as an account on Renec. Using fromSeed
, you can generate a Keypair using a deterministic constructor. fromSecret
creates a Keypair from a secret Uint8array. You can see that the publicKey for the generate
Keypair and fromSecret
Keypair are the same because the secret from the generate
Keypair is used in fromSecret
.
Warning: Do not use fromSeed
unless you are creating a seed with high entropy. Do not share your seed. Treat the seed like you would a private key.
#
PublicKeyPublicKey is used throughout @solana/web3.js
in transactions, keypairs, and programs. You require publickey when listing each account in a transaction and as a general identifier on Renec.
A PublicKey can be created with a base58 encoded string, buffer, Uint8Array, number, and an array of numbers.
#
Example Usage#
SystemProgramThe SystemProgram grants the ability to create accounts, allocate account data, assign an account to programs, work with nonce accounts, and transfer lamports. You can use the SystemInstruction class to help with decoding and reading individual instructions
#
Example Usage#
Secp256k1ProgramThe Secp256k1Program is used to verify Secp256k1 signatures, which are used by both Bitcoin and Ethereum.
#
Example Usage#
MessageMessage is used as another way to construct transactions. You can construct a message using the accounts, header, instructions, and recentBlockhash that are a part of a transaction. A Transaction is a Message plus the list of required signatures required to execute the transaction.
#
Example Usage#
StructThe struct class is used to create Rust compatible structs in javascript. This class is only compatible with Borsh encoded Rust structs.
#
Example UsageStruct in Rust:
Using web3:
#
EnumThe Enum class is used to represent a Rust compatible Enum in javascript. The enum will just be a string representation if logged but can be properly encoded/decoded when used in conjunction with Struct. This class is only compatible with Borsh encoded Rust enumerations.
#
Example UsageRust:
Web3:
#
NonceAccountNormally a transaction is rejected if a transaction's recentBlockhash
field is too old. To provide for certain custodial services, Nonce Accounts are used. Transactions which use a recentBlockhash
captured on-chain by a Nonce Account do not expire as long at the Nonce Account is not advanced.
You can create a nonce account by first creating a normal account, then using SystemProgram
to make the account a Nonce Account.
#
Example UsageThe above example shows both how to create a NonceAccount
using SystemProgram.createNonceAccount
, as well as how to retrieve the NonceAccount
from accountInfo. Using the nonce, you can create transactions offline with the nonce in place of the recentBlockhash
.
#
VoteAccountVote account is an object that grants the capability of decoding vote accounts from the native vote account program on the network.
#
Example Usage#
Staking#
StakeProgramThe StakeProgram facilitates staking RENEC and delegating them to any validators on the network. You can use StakeProgram to create a stake account, stake some RENEC, authorize accounts for withdrawal of your stake, deactivate your stake, and withdraw your funds. The StakeInstruction class is used to decode and read more instructions from transactions calling the StakeProgram
#
Example Usage#
AuthorizedAuthorized is an object used when creating an authorized account for staking within Renec. You can designate a staker
and withdrawer
separately, allowing for a different account to withdraw other than the staker.
You can find more usage of the Authorized
object under StakeProgram
#
LockupLockup is used in conjunction with the StakeProgram to create an account. The Lockup is used to determine how long the stake will be locked, or unable to be retrieved. If the Lockup is set to 0 for both epoch and the Unix timestamp, the lockup will be disabled for the stake account.
#
Example UsageThe above code creates a createStakeAccountInstruction
to be used when creating an account with the StakeProgram
. The Lockup is set to 0 for both the epoch and Unix timestamp, disabling lockup for the account.
See StakeProgram for more.