This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "use client"; | |
| import type React from "react"; | |
| import { useState, useEffect, useRef } from "react"; | |
| import { | |
| EdgeLabelRenderer, | |
| getBezierPath, | |
| getSimpleBezierPath, | |
| getSmoothStepPath, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mkdir real-time-chat | |
| cd real-time-chat | |
| npm init -y |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "use strict"; | |
| var __awaiter = | |
| (this && this.__awaiter) || | |
| function (thisArg, _arguments, P, generator) { | |
| function adopt(value) { | |
| return value instanceof P | |
| ? value | |
| : new P(function (resolve) { | |
| resolve(value); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async getUtxos(symbol: string, fromAddress: string) { | |
| let url = `https://api.blockcypher.com/v1/${symbol}/main/addrs/${fromAddress}?unspentOnly=true`; | |
| const res = await axios.get(url); | |
| if (res.data.txrefs) { | |
| let utxos = await res.data.txrefs.map((o: any) => ({ | |
| txId: o.tx_hash, | |
| vout: parseInt(o.tx_output_n), | |
| value: parseInt(o.value), | |
| })); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async broadcastTx(rawTx: any) { | |
| const res = await axios.post( | |
| `https://api.blockcypher.com/v1/btc/main/txs/push`, | |
| { | |
| tx: rawTx, | |
| }, | |
| ); | |
| return res.data; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async sendBTCNativeSegwitTransaction( | |
| txPayload: { | |
| from?: string; | |
| to?: string; | |
| amount: number; | |
| private_key: string; | |
| }, | |
| isTotalTransfer = false, | |
| ) { | |
| try { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async sendSegwitTrx( | |
| txPayload: { | |
| from?: string; | |
| to?: string; | |
| amount: number; | |
| private_key: string; | |
| }, | |
| isTotalTransfer = false, | |
| ) { | |
| try { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async sendLegacyTransaction( | |
| senderKey: string, | |
| amount: number, | |
| receiver: string, | |
| ) { | |
| try { | |
| const sender = bitcoin.ECPair.fromWIF(senderKey); | |
| const networkFee = await this.getBTCNetworkFees({ | |
| to: receiver, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async getFinalNoOfUTXOInputs( | |
| minerFee: number, | |
| amount: number, | |
| utxos: any[], | |
| finalBalance: number, | |
| unconfirmedBalance: number, | |
| ) { | |
| if (finalBalance < Number(amount) + minerFee) { | |
| throw new Error('Insufficient balance for Transaction'); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async getUtxos(symbol: string, fromAddress: string) { | |
| let url = `https://api.blockcypher.com/v1/${symbol}/main/addrs/${fromAddress}?unspentOnly=true`; | |
| const res = await axios.get(url); | |
| if (res.data.txrefs) { | |
| let utxos = await res.data.txrefs.map((o: any) => ({ | |
| txId: o.tx_hash, | |
| vout: parseInt(o.tx_output_n), | |
| value: parseInt(o.value), | |
| })); |
NewerOlder