GithubHelp home page GithubHelp logo

h4x0rlol / crypto-interaction Goto Github PK

View Code? Open in Web Editor NEW

This project forked from netsyde/crypto-interaction

1.0 1.0 0.0 110 KB

Crypto interaction

License: MIT License

JavaScript 49.46% TypeScript 50.54%

crypto-interaction's Introduction

Crypto interaction

Build Status Community Chat

About crypto interaction

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.

Features

  • Сreate multi-signature wallets
  • Сreate and send transactions from a multi signature wallet
  • TypeScript typings

Shortcuts

Install

yarn

  • yarn add crypto-interaction

npm

  • npm i crypto-interaction

Usage

Create multisignature wallet

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)

Create transaction and sign it

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()

API

Msint

Msint - utility module, containing the following functions:

generateKeyPairs

Function for generating KeyPairs.

Usage
import { bitcoin } from 'crypto-interaction';

let NETWORK = bitcoin.networks.testnet;

const msint = new bitcoin.Msint(NETWORK);
const keyPairs = msint.generateKeyPairs();

pubKeysFromKeyPairs

Function for getting public keys from KeyPairs.

Args
  • keyPairs
Usage
const publicKeys = msint.pubKeysFromKeyPairs(keyPairs);

getRedeemScript

Function for generating Redeem Script.

Args
  • pubKeys
Usage
const redeemScript = msint.getRedeemScript(pubKeys);

keyPairsFromWIFs

Function for getting key pairs from WIFs.

Args
  • WIFs
Usage
let keyPairs = msint.keyPairsFromWIFs(WIFs);

bufferFromHex

Function for getting Buffer from Hex.

Args
  • hex
Usage
let buffer = msint.bufferFromHex(hex);

Wallet

Wallet - module for interacting with the wallet, containing the following functions:

create

Function for creating an address.

Usage
import { bitcoin } from 'crypto-interaction';
let NETWORK = bitcoin.networks.testnet

const wallet = new bitcoin.Wallet(NETWORK, keyPairs);
const address = wallet.create();

getInfo

Function for getting information about the wallet.

Usage
const Info = wallet.getInfo();

const address = info.address;
const redeem = info.redeem;
const WIFs = info.WIFs;
const pubKeys = info.pubKeys;

Transaction

Transaction - module for creating and interacting with transactions, which includes the following functions:

create

Function for creating a transaction.

Usage
import { bitcoin } from 'crypto-interaction';
let NETWORK = bitcoin.networks.testnet;

const tx = new bitcoin.Transaction(NETWORK).create();

addInput

Function for adding input to a transaction.

Args
  • hash - hash of the previous transaction
  • script - script pub key
  • balance
Usage
tx.addInput(hash, script, balance);

addOutput

Function for adding output to a transaction.

Args
  • recipient - recipient address
  • balance
  • fee - transaction fee
Usage
tx.addOutput(recipient, balance, fee);

sign

Function for signing a transaction.

Args
  • WIF
Usage
tx.sign(key1);
tx.sign(key2);

broadcast

Function publishes the transaction to the blockchain.

Usage
tx.broadcast()

NodeInt

NodeInt - module for interacting with the bitcoin blockchain via the fetch API, includes the following functions:

getHash

Function for getting the hash of the previous transaction.

Args
  • address
Usage
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);

getScriptPubKey

Function for getting the script public key.

Args
  • address
Usage
let script = await input.getScriptPubKey(address)

getBalance

Function for getting the address balance.

Args
  • address
Usage
let balance = await input.getBalance(address);

crypto-interaction's People

Contributors

sgoldik avatar dependabot[bot] avatar h4x0rlol avatar

Stargazers

Roman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.