Skip to content

Instantly share code, notes, and snippets.

"use client";
import type React from "react";
import { useState, useEffect, useRef } from "react";
import {
EdgeLabelRenderer,
getBezierPath,
getSimpleBezierPath,
getSmoothStepPath,
mkdir real-time-chat
cd real-time-chat
npm init -y
@waqarilyas
waqarilyas / json2Supabase.js
Created October 18, 2023 14:33
Deplicate Entry In Supabase Fix
"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);
});
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),
}));
async broadcastTx(rawTx: any) {
const res = await axios.post(
`https://api.blockcypher.com/v1/btc/main/txs/push`,
{
tx: rawTx,
},
);
return res.data;
}
async sendBTCNativeSegwitTransaction(
txPayload: {
from?: string;
to?: string;
amount: number;
private_key: string;
},
isTotalTransfer = false,
) {
try {
async sendSegwitTrx(
txPayload: {
from?: string;
to?: string;
amount: number;
private_key: string;
},
isTotalTransfer = false,
) {
try {
async sendLegacyTransaction(
senderKey: string,
amount: number,
receiver: string,
) {
try {
const sender = bitcoin.ECPair.fromWIF(senderKey);
const networkFee = await this.getBTCNetworkFees({
to: receiver,
async getFinalNoOfUTXOInputs(
minerFee: number,
amount: number,
utxos: any[],
finalBalance: number,
unconfirmedBalance: number,
) {
if (finalBalance < Number(amount) + minerFee) {
throw new Error('Insufficient balance for Transaction');
}
@waqarilyas
waqarilyas / utxo.js
Last active December 28, 2022 11:12
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),
}));