@investorphem/stx-utils
v1.0.2
Published
JavaScript utility library for interacting with the Stacks blockchain.
Maintainers
Readme
@investorphem/stx-utils
Description
@investorphem/stx-utils is a JavaScript utility library for interacting with the Stacks blockchain. It provides functions to send STX, read contract state, validate addresses, and convert STX units.
Features
- Send STX tokens programmatically
- Read-only contract calls
- Validate Stacks addresses
- Convert between STX and micro-STX
- Check account balances
- Fully automated GitHub Actions publishing workflow
Installation
npm install @investorphem/stx-utils
npm install @stacks/transactions @stacks/network @stacks/cryptoUsage
const { stxToMicro, microToStx, isValidAddress, sendSTX } = require('@investorphem/stx-utils');
console.log(stxToMicro(1.5)); // 1500000n
console.log(microToStx(1500000n)); // 1.5
console.log(isValidAddress('ST3J2GVMMM2R07ZFBJDWTYEYAR8FZH5WKDTFJ9AHA')); // true
// Sending STX (async)
(async () => {
const result = await sendSTX('<private-key>', 'ST3J2GVMMM2R07ZFBJDWTYEYAR8FZH5WKDTFJ9AHA', 0.1, 'testnet');
console.log(result);
})();API
stxToMicro(amount)
Converts STX to micro-STX.
microToStx(amount)
Converts micro-STX to STX.
isValidAddress(address)
Validates a Stacks address.
sendSTX(senderKey, recipient, amount, network)
Sends STX tokens from a private key to a recipient.
Parameters:
senderKey(string) – private key of senderrecipient(string) – STX address of recipientamount(number) – STX amountnetwork(string) – 'testnet' or 'mainnet' (default: testnet)
Returns:
- Promise resolving to transaction result
Contributing
Contributions are welcome! Fork the repo, make improvements, and submit a pull request. Ensure code follows StandardJS style.
License
MIT License
Maintained by Oluwafemi Olagoke
