A minimal JavaScript library for sending crypto assets.
Supported assets
Usage
npm install --save @joshyzou/sendcrypto
Replace "btc" with any supported asset:
const Accounts = require("@joshyzou/sendcrypto");
/* Load account from private key, select crypto API provider, coin. ApiKey is optional*/
const account = new Accounts(address, privateKey, "btc", apiProvider, apiKey);
/* Print balance */
console.log(await account.getBalance());
// > 0.01
/* Send 0.01 BTC */
const txHash = await account.send("Reciever address", 0.01, "Eth Gas (Only applies to ethereum)")
// > 1
// > 2 ...
Docs
When creating a new account, there are 4 required parameters and 1 optional parameter.
new Accounts(crypto_address, crypto_secret, coin, api_provider, api_key-optional);
crypto_address
This is your crypto address. For example, a bitcoin address looks like 1KHwtS5mn7NMUm7Ls7Y1XwxLqMriLdaGbX
crypto_secret
This is your crypto secret. You need this to prove to the network that you are the owner of the coin, which then enables you to send crypto to other wallets.
coin
Supported assets - use the lowercase ticker in the "coin" parameter
Coin | Ticker |
---|---|
BITCOIN | btc |
ETHEREUM | eth |
LITECOIN | ltc |
RIPPLE | xrp |
api_provider
This is the api provider you would like to use to interact with the rest of the blockchain.
Supported BTC apis
API | Key required? | send_crypto parameter name |
---|---|---|
Sochain | No | sochain |
Blockcypher | Yes | blockcypher |
Supported ETH apis
API | Key required? | send_crypto parameter name |
---|---|---|
Etherscan | Yes | etherscan |
Blockcypher | Yes | blockcypher |
Web3 | Yes* | web3 |
*note: If you would like to use your own web3 server, (like infura) the "key" parameter is your connection string/url
Supported LTC apis
API | Key required? | send_crypto parameter name |
---|---|---|
Sochain | No | sochain |
Supported XRP apis
API | Key required? | send_crypto parameter name |
---|---|---|
Ripple.API | Yes* | ripple.api |
*note: If you would like to use your own ripple API serverthe "key" parameter is your connection string/url - The public no-key-required api service is wss://s1.ripple.com
Sending transactions
When sending transactions, there are normally 2 parameters, with an optional third for ETH
account.send(reciever, amountToSend, *gas*)
reciever
The reciever address you would like to send the crypto to.
amountToSend
This is the amount of crypto you would like to send
If you would like to send all of the crypto in your wallet (Sweeping) pass "all" as a string instead of a number in this parameter
gas
The max gas you would like to be consumed in ETH transactions. The default is 2100 gwei, but you can increase/decrease this number as you please.
Examples
BTC, LTC
const Accounts = require("@joshyzou/sendcrypto");
// Send BTC
const account = new Accounts("BTC Address", "BTC Secret", "btc", "sochain");
await account.send("reciever address", 0.01);
const Accounts = require("@joshyzou/sendcrypto");
// Send LTC
const account = new Accounts("LTC Address", "LTC Secret", "ltc", "sochain");
await account.send("reciever address", 0.01);
You can replace "BTC"
with "ZEC"
or "BCH"
in the following examples:
const Accounts = require("@joshyzou/sendcrypto");
// Send LTC
const account = new Accounts("BTC Address", "BTC Secret", "btc", "sochain");
await account.send("reciever address", "all");
ETH
const Accounts = require("@joshyzou/sendcrypto");
// Send ETH
const account = new Accounts("ETH Address", "ETH Secret", "eth", "web3", "web3 connection string");
await account.send("reciever address", 0.01, 2100);