Giter VIP home page Giter VIP logo

solanaj's Introduction

solanaj

Updated version of p2p-org/solanaj Solana lightweight blockchain client, written in pure Java. Solanaj is an API for integrating with Solana blockchain using the Solana RPC API

Requirements

  • Java 11+

Dependencies

Usage

create wallet

        // the netowrk, MAINNET or TESTNET
        final Network network = Network.TESTNET;

        // your mnemonic phrase
        final String mnemonic = "swing brown giraffe enter common awful rent shock mobile wisdom increase banana";

        // optional passphrase
        final String passphrase = null;

        // create wallet
        SolanaWallet solanaWallet = new SolanaWallet(mnemonic, passphrase, network);
        
        // get address (account, chain, index), used to receive
        solanaWallet.getAddress(0, Chain.EXTERNAL, null);
        
        // get private key (account, chain, index), used to sign transactions 
        solanaWallet.getPrivateKey(0, Chain.EXTERNAL, null);

Sign and send a transaction

        // create new SolanaRpcClient, (DEVNET, TESTNET, MAINNET)
        SolanaRpcClient client = new SolanaRpcClient(Cluster.DEVNET);
        
        // wallet address of the receiver
        String receiverAddress = "EPBkAFmzU6CajVCjz2Jd3H5MZ7CuZz74UjuWK1MUtFtV";
        
        // amount to transfer in lamports, 1 SOL = 1000000000 lamports
        long amount = 1000000000;
        
        // create new transaction
        SolanaTransaction transaction = new SolanaTransaction();

        // create solana account, this account holds the funds that we want to transfer
        SolanaAccount account = new SolanaAccount(solanaWallet.getPrivateKey(0, Chain.EXTERNAL, null));
         
        // define the sender and receiver public keys
        SolanaPublicKey fromPublicKey = account.getPublicKey();
        SolanaPublicKey toPublickKey = new SolanaPublicKey(receiverAddress);

        // add instructions to the transaction (from, to, lamports)
        transaction.addInstruction(SystemProgram.transfer(fromPublicKey, toPublickKey, amount));
        
        // set the recent blockhash
        transaction.setRecentBlockHash(client.getApi().getRecentBlockhash());
        
        // set the fee payer
        transaction.setFeePayer(account.getPublicKey());
        
        // sign the transaction
        transaction.sign(account);
        
        // publish the transaction
        String signature = client.getApi().sendTransaction(transaction);

Listen for account updates

        String walletAddress = "EPBkAFmzU6CajVCjz2Jd3H5MZ7CuZz74UjuWK1MUtFtV";
        websocket.accountSubscribe(walletAddress, data -> {
            System.out.println("update received");
        });

License

Solanaj is available under the MIT license. See the LICENSE file for more info.

solanaj's People

Contributors

abdullahasendar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

solanaj's Issues

about create wallet

    // create wallet
    SolanaWallet solanaWallet = new SolanaWallet(mnemonic, passphrase, network);

The problem is how the mnemonic is generated in the first place

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.