Add dependencies
The @solana/web3.js library provides convenient classes and Solana primitive types to build transactions.Add polyfills
After installing, ensure you have also added these polyfills to your React native app. These are needed by some parts of@solana/web3.js because it is originally written as a web/node library and, as a result, certain expected APIs are missing in a React Native environment.
Example: SOL Transfer Transaction
In the following example, we create a transaction that invokes the System Program’s transfer instruction to send SOL to an address. A transaction instruction is comprised of a program id, a list of accounts, and instruction data specific to the program.- Versioned Transactions
- Legacy Transactions
A versioned transaction is a new format for transactions recommended for use by clients.As an example, we’ll be invoking the transfer instruction from the System Program. Use the
SystemProgram factory class
to conveniently generate the transfer instruction.Send a Transaction
After a transaction is signed by the appropriate accounts, it can be submitted to the Solana network via RPC. See the next guide, Using Mobile Walelt Adapter to learn how to sign transactions.- Versioned Transactions
- Legacy Transactions
Next steps
- Read the following Using Mobile Wallet Adapter guide to learn how to sign these transactions and submit them to the Solana network.
- See the Anchor Integration guide to learn how to create and create transactions and invoke instructions from Anchor programs.
