Class SolanaRpc

java.lang.Object
com.codename1.crypto.rpc.JsonRpc
com.codename1.crypto.rpc.SolanaRpc

public class SolanaRpc extends JsonRpc

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 Details

  • Constructor Details

    • SolanaRpc

      public SolanaRpc(RpcTransport transport, String url)
      A client reading at confirmed.
    • SolanaRpc

      public SolanaRpc(RpcTransport transport, String url, String commitment)
      A client reading at a commitment: processed, confirmed or finalized.
  • Method Details

    • getBalance

      public long getBalance(SolanaAddress address) throws IOException
      getBalance in lamports.
      Throws:
      IOException
    • getLatestBlockhash

      public String getLatestBlockhash() throws IOException
      getLatestBlockhash: the Base58 blockhash for a new message.
      Throws:
      IOException
    • getLastValidBlockHeight

      public long getLastValidBlockHeight() throws IOException
      The block height after which a transaction using the latest blockhash expires.
      Throws:
      IOException
    • getMinimumBalanceForRentExemption

      public long getMinimumBalanceForRentExemption(long space) throws IOException
      getMinimumBalanceForRentExemption for an account of space bytes.
      Throws:
      IOException
    • getTokenAccountBalance

      public String getTokenAccountBalance(SolanaAddress tokenAccount) throws IOException
      getTokenAccountBalance: the raw amount in base units, as the decimal string the node answers (a token amount may exceed a signed long).
      Throws:
      IOException
    • accountExists

      public boolean accountExists(SolanaAddress address) throws IOException
      Whether an account exists, which a sender checks before paying to create the recipient's token account.
      Throws:
      IOException
    • sendTransaction

      public String sendTransaction(SolanaTransaction signed) throws IOException
      sendTransaction with preflight at this client's commitment, answering the signature (the transaction id).
      Throws:
      IOException
    • getSignatureStatus

      public String getSignatureStatus(String signature) throws IOException
      getSignatureStatuses for one signature: null when the cluster has not seen it, otherwise its confirmationStatus (processed, confirmed, finalized), or "failed" when it landed with an error.
      Throws:
      IOException
    • requestAirdrop

      public String requestAirdrop(SolanaAddress to, long lamports) throws IOException
      requestAirdrop on devnet or testnet, answering the airdrop's signature.
      Throws:
      IOException