@getsafle/vault-solana-controller

1.0.0 • Public • Published

vault-solana-controller

Install

npm install --save @getsafle/vault-solana-controller

Initialize the Solana Controller class

const { KeyringController, getBalance } = require('@getsafle/vault-solana-controller');

const solanaController = new KeyringController({
    // 12 words mnemonic to create wallet
    mnemonic: string,
    // network - type of network [TESTNET|MAINNET|DEVNET]
    // default is MAINNET even if no network is passed
    network: string (TESTNET | MAINNET | DEVNET)
});

Methods

Generate Keyring with 1 account or add new account

const keyringState = await solanaController.addAccount();

Export the private key of an address present in the keyring

const privateKey = await solanaController.exportPrivateKey(address);

Get all accounts in the keyring

const privateKey = await solanaController.getAccounts();

Sign a transaction

const signedTx = await solanaController.signTransaction(solanaTx: TransactionObj);

solanaTx: {from, to, amount}
  1. SOL transfer:
    Trasaction to transfer SOL from one wallet/address to another.
    The transaction object is of the following type:
TransactionObj: {
    data: {
        to, // destination address
        amount, // amount
    },
    txnType: NATIVE_TRANSFER, // type constant
    from: // sender address
}
  1. SPL token transfer:
    Transaction to transfer SPL tokens from one wallet/address to another.
    The transaction object is of the following type:
TransactionObj: {
    data: {
        to, // destination address
        amount // amount to send
        memo // any memo send by user
        token // token address
    },
    txnType: TOKEN_TRANSFER, // type constant
    from: // sender address
}
  1. Contract transactions:
    Transaction to call any smart contract function.
    The transaction object is of the following type:
TransactionObj: {
    data: {
        programAccountKey, // address at which the program state is managed
        programId, // programId of the contract
        bufferData // data to send in buffer format
    },
    txnType: CONTRACT_TRANSACTION, // type constant
    from: // sender address
}
  1. Mint new SPL token:
    Transaction to mint new token with initial amount and decimal places.
    The transaction object is of the following type:
TransactionObj: {
    data: {
        amount: 1000, // amount
        decimals: 2, // decimal places
   },
   txnType: MINT_NEW_TOKEN, // type constant
   from: // sender address
}

parameters:

name: transaction,
type: TransactionObj, // refer to the above 4 transactionObj types.

returns: {signedTransaction: Buffer} signed raw transaction

Sign a message

const signedMsg = await solanaController.signMessage(msgString, address);

Get fees

const fees = await solanaController.getFee(address);

Get balance

const balance = await getBalance(address, network); // if network !== TESTNET then it will fetch mainnet balance

Readme

Keywords

Package Sidebar

Install

npm i @getsafle/vault-solana-controller

Weekly Downloads

0

Version

1.0.0

License

ISC

Unpacked Size

44.2 kB

Total Files

21

Last publish

Collaborators

  • subhanshugupta
  • apoorv31
  • shubham.3008
  • sidth