npm install --save @getsafle/vault-stacks-controller
const { KeyringController, getBalance } = require('@getsafle/vault-stacks-controller');
const stacksController = 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)
});
await stacksController.generateWallet();
const keyringState = await stacksController.addAccount();
const privateKey = await stacksController.exportPrivateKey(address);
const privateKey = await stacksController.getAccounts();
const signedTx = await stacksController.signTransaction(stacksTx);
STX transfer transaction:
stacksTx: {from, to, amount, transactionType, memo: (optional)}
Token transfer transaction:
stacksTx: {
from,
to,
amount,
transactionType,
contractDetails: { contractAddress, contractName, assetName },
memo: (optional)
}
transactionType = 'token_transfer' || 'contract_call'
const signedMsg = await stacksController.signMessage(msgString, address);
const fees = await stacksController.getFees(rawTransaction);
const balance = await getBalance(address, network); // if network !== TESTNET then it will fetch mainnet balance