solana_web3 0.0.3+2
solana_web3: ^0.0.3+2 copied to clipboard
Dart implementation of Solana's JSON RPC API with support for common Programs.
Dart implementation of Solana's JSON RPC API. #
Android and iOS support.

Screenshot of solana_wallet_provider
Implements the following programs: #
- System Program
- Token Program
- Associated Token Program
- Stake Program
- Stake Pool Program
- Memo Program
- Compute Budget Program
- ED25519 Program
Features include: #
- Signing Transactions.
- Sending Transactions.
- Signing Messages.
- Websocket Notification Subscriptions (e.g. Account changes).
- Keypair Generation.
- Borsh Serialization.
Example: Transfer SOL #
/// Imports
import 'package:solana_web3/solana_web3.dart' as web3;
import 'package:solana_web3/programs/system.dart';
/// Transfer tokens from one wallet to another.
void main(final List<String> _arguments) async {
// Create a connection to the devnet cluster.
final cluster = web3.Cluster.devnet;
final connection = web3.Connection(cluster);
// Create a wallet to transfer tokens from.
print('Creating accounts...\n');
final wallet1 = web3.Keypair.generate();
final address1 = wallet1.publicKey;
// Credit the wallet that will be sending tokens.
await connection.requestAirdropAndConfirmTransaction(
address1,
web3.solToLamports(2).toInt(),
);
// Create a wallet to transfer tokens to.
final wallet2 = web3.Keypair.generate();
final address2 = wallet2.publicKey;
// Check the account balances before making the transfer.
final balance = await connection.getBalance(address1);
print('Account $address1 has an initial balance of $balance lamports.');
print('Account $address2 has an initial balance of 0 lamports.\n');
// Create a System Program instruction to transfer 1 SOL from [address1] to [address2].
final transaction = web3.Transaction();
transaction.add(
SystemProgram.transfer(
fromPublicKey: address1,
toPublicKey: address2,
lamports: web3.solToLamports(1),
),
);
// Send the transaction to the cluster and wait for it to be confirmed.
print('Send and confirm transaction...\n');
await connection.sendAndConfirmTransaction(
transaction,
signers: [wallet1], // Fee payer + transaction signer.
);
// Check the updated account balances.
final balance1 = await connection.getBalance(address1);
final balance2 = await connection.getBalance(address2);
print('Account $address1 has an updated balance of $balance1 lamports.');
print('Account $address2 has an updated balance of $balance2 lamports.');
}
Bugs #
Report a bug by opening an issue.
Feature Requests #
Request a feature by raising a ticket.