TheCryptoGate.com Blockchain API (BTC, ...)
https://www.npmjs.com/package/the-crypto-gate
- Legend:
Install:
npm i the-crypto-gate --save
Require && set-up apiKey:
const theCryptoGate = ; const TCG = apiKey: '<my-key>';
Info: TheCryptoGate library is API-Ready
// expressapp;
"code": 200 "msg": "OK" "data": "balance": 000137764 "confirmed": 000137764 "unconfirmed": 0
Method: getAddressBalance
Success
const balanceRes = await TCG); "code": 200 "msg": "OK" "data": "balance": 000137764 "confirmed": 000137764 "unconfirmed": 0
Error or Warning
const balanceRes = await TCG); "code": <int> // !200 "msg": "Description ..." "data": {}
Method: getAddressUnspent
Get all unspent transactions (UTXO) from Address
WARNING:
Only for advanced users. You can lose all your Crypto
Success
const res = await TCG); "code": 200 "msg": "OK" "data": "tx_hash": "c81bdf7a1caeffa7340613da5d01929b24a7de66b499874f1f23a072bebd3935" "tx_pos": 1 "height": 575219 "value": 137764 // amount ins Sat. "balance": 000137764
Error or Warning
const res = await TCG); "code": <int> // !200 "msg": "Description ..." "data": {}
Method: pushRawTransaction
Broadcast your created Transaction into the Blockchain
Success
const res = await TCG); "code": 200 "msg": "OK" "data": // Pushed transaction hash "hash": "c81bdf7a1caeffa7340613da5d01929b24a7de66b499874f1f23a072bebd3935"
Error or Warning
const res = await TCG); "code": <code> // !200 "msg": "Transaction already in block chain" "data": {}
Method: getTransactionByHash
Fetch transaction from Blockchain by hash,
Success
const res = await TCG); "code": 200 "msg": "OK" "data": "transaction": "txid": "c81bdf7a1caeffa7340613da5d01929b24a7de66b499874f1f23a072bebd3935" "hash": "c81bdf7a1caeffa7340613da5d01929b24a7de66b499874f1f23a072bebd3935" "version": 2 "size": 226 "vsize": 226 "weight": 904 "locktime": 0 "vin": ... ...
Error or Warning
const res = await TCG); "code": 400 "msg": "Not valid Transaction Hash" "data": {}
"code": 500 "msg": "No such mempool or blockchain transaction. Use gettransaction for wallet transactions" "data": {}
Method: getBlockByID
Success
const res = await TCG; "code": 200 "msg": "OK" "data": ...
Error or Warning
"code": <int> // !200 "msg": "Description ..." "data": {}
Method: estimateSmartFee
Get the best transaction fee for the moment.
Within next blocks: Min 2, Max Inf.
The lower <withInNextBlocks>, the heigher <tx-fee> will be
Success
const res = await TCG; "code": 200 "msg": "OK" "data": "perKiloByte": 000081461 "perByte": 795518e-7 "avgTxBytes": 195 "avgTxCoastBtc": 000015513 "withInNextBlocks": 2
Error or Warning
"code": <int> // !200 "msg": "Description ..." "data": {}
Method: getKeyPair
Create new (random) CryptoPair => Public && Private key
WARNING:
You must store it in your own database or you will lose all your Crypto
Success
const KeyPair = await TCG; "code": 200 "msg": "OK" "data": "symbol": "BTC" "sec_key": "L1xx81HHJhNFJdmU5soiL1SbYzmZ6Anu8GdtiUE7GDifzViy6rwj" "pub_key": "1MD1LWPp3uj53ithDs9ygMi2tFkB3vt27V" "encrypted": false
Error or Warning
"code": <int> // !200 "msg": "Description ..." "data": {}
Info: Create && Broadcast Transaction
options (optional):
-
allowDust: Allow send vary small amount (dust)
-
feeType: Try send within next blocks. Can be any of ( 2,3,4,5,6 ). Default: 3
-
tryToFitTxFee: if amount plus Tx-Fee is less than total balance, it will try reduce dest. amount to fit transaction cost in transaction itself. NOTE: Works only if dest object contains 1 dest. address
Send to many ...
const sendOutToMany = address: '1GPwAmZFSZ3vFy1mfJqpDcNqrmXZjMxYV' amount: 0034 address: '1mfJqpDcNqrmXZjMxYV1GPwAmZFSZ3vFy' amount: 0012 address: '1mZFSZ3vFyfJqpDcNqrmXZjMxYVm1GPwA' amount: 0787;
Send to one ...
const sendOutToOne = address: '1GPwAmZFSZ3vFy1mfJqpDcNqrmXZjMxYV' amount: +aliceBalanceResdatabalance ;
const aliceBalanceRes = await TCG; // Optianal: optionsconst options = allowDust: false feeType: 3 tryToFitTxFee: true; const sendOutToOne = address: '1GPwAmZFSZ3vFy1mfJqpDcNqrmXZjMxYV' amount: +aliceBalanceResdatabalance ; const TxRes = await TCG; code: 200 msg: 'Transaction is ready to be broadcasted' data: raw_tx: 'abcd234569cdef......' if TxRescode !== 200 console; return;
Broadcast transaction into Blockchain
const pushRawTxRes = await TCG; if pushRawTxRescode !== 200 console; return; // Successconsole;