Class SolanaRpc
java.lang.Object
com.codename1.crypto.rpc.JsonRpc
com.codename1.crypto.rpc.SolanaRpc
A Solana JSON-RPC client: balances, the recent blockhash a transaction needs, rent, token balances, sending and confirmation.
SolanaRpc sol = new SolanaRpc(new NetworkTransport(), SolanaRpc.DEVNET);
Wallet wallet = Wallet.fromMnemonic(Mnemonic.generate(128), "");
SolanaAddress me = wallet.getSolanaAddress(0);
List<Instruction> instructions = new ArrayList<Instruction>();
instructions.add(SystemProgram.transfer(me, me, 1000000L));
SolanaMessage m = SolanaMessage.compile(me, instructions, sol.getLatestBlockhash());
SolanaTransaction tx = new SolanaTransaction(m);
wallet.signSolanaTransaction(tx, 0);
String signature = sol.sendTransaction(tx);
Reads use the commitment given to the constructor; confirmed by default.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSolanaRpc(RpcTransport transport, String url) A client reading atconfirmed.SolanaRpc(RpcTransport transport, String url, String commitment) A client reading at a commitment:processed,confirmedorfinalized. -
Method Summary
Modifier and TypeMethodDescriptionbooleanaccountExists(SolanaAddress address) Whether an account exists, which a sender checks before paying to create the recipient's token account.longgetBalance(SolanaAddress address) getBalancein lamports.longThe block height after which a transaction using the latest blockhash expires.getLatestBlockhash: the Base58 blockhash for a new message.longgetMinimumBalanceForRentExemption(long space) getMinimumBalanceForRentExemptionfor an account ofspacebytes.getSignatureStatus(String signature) getSignatureStatusesfor one signature:nullwhen the cluster has not seen it, otherwise itsconfirmationStatus(processed,confirmed,finalized), or"failed"when it landed with an error.getTokenAccountBalance(SolanaAddress tokenAccount) getTokenAccountBalance: the raw amount in base units, as the decimal string the node answers (a token amount may exceed a signedlong).requestAirdrop(SolanaAddress to, long lamports) requestAirdropon devnet or testnet, answering the airdrop's signature.sendTransaction(SolanaTransaction signed) sendTransactionwith preflight at this client's commitment, answering the signature (the transaction id).
-
Field Details
-
MAINNET
-
DEVNET
-
TESTNET
-
-
Constructor Details
-
SolanaRpc
A client reading atconfirmed. -
SolanaRpc
A client reading at a commitment:processed,confirmedorfinalized.
-
-
Method Details
-
getBalance
getBalancein lamports.- Throws:
IOException
-
getLatestBlockhash
getLatestBlockhash: the Base58 blockhash for a new message.- Throws:
IOException
-
getLastValidBlockHeight
The block height after which a transaction using the latest blockhash expires.- Throws:
IOException
-
getMinimumBalanceForRentExemption
getMinimumBalanceForRentExemptionfor an account ofspacebytes.- Throws:
IOException
-
getTokenAccountBalance
getTokenAccountBalance: the raw amount in base units, as the decimal string the node answers (a token amount may exceed a signedlong).- Throws:
IOException
-
accountExists
Whether an account exists, which a sender checks before paying to create the recipient's token account.- Throws:
IOException
-
sendTransaction
sendTransactionwith preflight at this client's commitment, answering the signature (the transaction id).- Throws:
IOException
-
getSignatureStatus
getSignatureStatusesfor one signature:nullwhen the cluster has not seen it, otherwise itsconfirmationStatus(processed,confirmed,finalized), or"failed"when it landed with an error.- Throws:
IOException
-
requestAirdrop
requestAirdropon devnet or testnet, answering the airdrop's signature.- Throws:
IOException
-