Skip to content

Latest commit

 

History

History
79 lines (52 loc) · 2.07 KB

README.MD

File metadata and controls

79 lines (52 loc) · 2.07 KB

vault-SOL-controller

npm version Static Badge Discussions Static Badge

Install

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

Initialize the solana Controller class

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

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

Methods

add new account

const keyringState = await solController.addAccount();

Export the private key of an address present in the keyring

const privateKey = await solController.exportPrivateKey(address);

Get all accounts in the keyring

const privateKey = await solController.getAccounts();

Sign a transaction

const signedTx = await solController.signTransaction(solTx);

STX transfer transaction:
solTx: {from, to, amount, txnType}

Token transfer transaction:
solTx: {from, to, amount, txnType, token}

transactionType = 'NATIVE_TRANSFER' || 'TOKEN_TRANSFER'

Sign a message

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

Get fees

const fees = await solController.getFees(rawTransaction);

Get balance

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