Crypto interaction is a module of the crypto2bot that allows you to interact with the Bitcoin blockchain. It is planned to support other cryptocurrencies, such as Ethereum, Litecoin, etc.
The module is currently under active development, so we dont recommend using it in production.
- Сreate multi-signature wallets
- Сreate and send transactions from a multi signature wallet
- TypeScript typings
- yarn add crypto-interaction
- npm i crypto-interaction
import { bitcoin } from 'crypto-interaction';
const testnet = bitcoin.networks.testnet;
const keyPairs = new bitcoin.Msint(testnet).generateKeyPairs();
const wallet = new bitcoin.Wallet(testnet, keyPairs);
const address = wallet.create();
console.log(address)
import { bitcoin } from 'crypto-interaction';
const testnet = new bitcoin.Network().getTestnet()
const FEE = 10000;
const tx = new bitcoin.Transaction(testnet).create();
let input = new bitcoin.NodeInt(API);
let hash = await input.getHash(address);
console.log(hash);
const key1 = 'cMorAV1Ww74rbQAq1v5LRahB7BQ7LQNAThiJjtum1BepXzxnQ38x'
const key2 = 'cVzM1Ukhx3pwvyAikBEnUvN8vNeviRdswuZFP6cwiLxpg7j1t8wY'
let script = await input.getScriptPubKey(address)
console.log(script)
let balance = await input.getBalance(address)
console.log(balance)
// Gets hash, script and fullAmount and after ->
tx.addInput(hash, script, balance)
// Gets buyer address, amount and after ->
const recipient = 'tb1qxs488h7tmk5w6axeht5zvgwts8w48s2fhge4yskmv8pskdplsdesquf922';
// const transferAmount = 10000
tx.addOutput(recipient, balance, FEE)
// waiting for confirmation and after sign tx (1/3)
tx.sign(key1)
// waiting for confirmation and after sign tx (2/3)
tx.sign(key2)
// finalize and broadcast
tx.broadcast()
Msint - utility module, containing the following functions:
Function for generating KeyPairs.
import { bitcoin } from 'crypto-interaction';
let NETWORK = bitcoin.networks.testnet;
const msint = new bitcoin.Msint(NETWORK);
const keyPairs = msint.generateKeyPairs();
Function for getting public keys from KeyPairs.
- keyPairs
const publicKeys = msint.pubKeysFromKeyPairs(keyPairs);
Function for generating Redeem Script.
- pubKeys
const redeemScript = msint.getRedeemScript(pubKeys);
Function for getting key pairs from WIFs.
- WIFs
let keyPairs = msint.keyPairsFromWIFs(WIFs);
Function for getting Buffer from Hex.
- hex
let buffer = msint.bufferFromHex(hex);
Wallet - module for interacting with the wallet, containing the following functions:
Function for creating an address.
import { bitcoin } from 'crypto-interaction';
let NETWORK = bitcoin.networks.testnet
const wallet = new bitcoin.Wallet(NETWORK, keyPairs);
const address = wallet.create();
Function for getting information about the wallet.
const Info = wallet.getInfo();
const address = info.address;
const redeem = info.redeem;
const WIFs = info.WIFs;
const pubKeys = info.pubKeys;
Transaction - module for creating and interacting with transactions, which includes the following functions:
Function for creating a transaction.
import { bitcoin } from 'crypto-interaction';
let NETWORK = bitcoin.networks.testnet;
const tx = new bitcoin.Transaction(NETWORK).create();
Function for adding input to a transaction.
- hash - hash of the previous transaction
- script - script pub key
- balance
tx.addInput(hash, script, balance);
Function for adding output to a transaction.
- recipient - recipient address
- balance
- fee - transaction fee
tx.addOutput(recipient, balance, fee);
Function for signing a transaction.
- WIF
tx.sign(key1);
tx.sign(key2);
Function publishes the transaction to the blockchain.
tx.broadcast()
NodeInt - module for interacting with the bitcoin blockchain via the fetch API, includes the following functions:
Function for getting the hash of the previous transaction.
- address
const API = 'https://api.blockcypher.com/v1/btc/test3'
const address = wallet.create();
let input = new bitcoin.NodeInt(API);
let hash = await input.getHash(address);
Function for getting the script public key.
- address
let script = await input.getScriptPubKey(address)
Function for getting the address balance.
- address
let balance = await input.getBalance(address);