Comments (2)
Please post your versions for node, npm, etc. and create a minimal reproduction that we can try to reproduce.
from coinselect.
Please post your versions for node, npm, etc. and create a minimal reproduction that we can try to reproduce.
Npm v 9.8.0
Node v 20.9.0
this is the error it gives below
Could not find a declaration file for module 'coinselect'. 'c:/Users/USER/Desktop/Richie_Exchange/node_modules/coinselect/index.js' implicitly has an 'any' type.
Try npm i --save-dev @types/coinselect
if it exists or add a new declaration (.d.ts) file containing declare module 'coinselect';
ts(7016)
module "c:/Users/USER/Desktop/Richie_Exchange/node_modules/coinselect/index"
/////////////222///////
Below is my package.json file
{
"name": "richie_exchange",
"version": "1.0.0",
"description": "",
"main": "app",
"type": "module",
"esModuleInterop": true,
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^1.4.0",
"bip32": "^4.0.0",
"bip39": "^3.1.0",
"bitcoinjs-lib": "^6.1.3",
"coinselect": "^3.1.13",
"dotenv": "^16.3.1",
"ecpair": "^2.1.0",
"express": "^4.18.2",
"got": "^13.0.0",
"tiny-secp256k1": "^2.2.3"
}
}
////////://:::::::::::::::::////////
And this is my code
import bitcoin, { Psbt } from 'bitcoinjs-lib';
import coinSelect from 'coinselect'
import ECPairFactory from 'ecpair';
import * as ecc from 'tiny-secp256k1';
const ECPair = ECPairFactory.ECPairFactory(ecc);
import btcFunctions from './function/bitcoin_service.js';
import { config } from 'dotenv';
const createTransactionTX = {
async CreateTX(publicKeyFrom, privateKeyFrom, publicKeyTo, changeAddress, amoutTosend, network) {
if (network == "test") {
var btcNetwork = bitcoin.networks.testnet;
} else {
btcNetwork = bitcoin.networks.bitcoin;
}
const data = await btcFunctions.getBalance(publicKeyFrom, network);
if (!data) {
return;
}
var balance = data.balance; // + data.unconfirmed_balance, should not be able to spend from uncomfirmed balance
if (balance > amoutTosend) {
const unspentOutputs = await btcFunctions.getUnspentOutputs(publicKeyFrom, network);
if (!unspentOutputs) {
return;
}
const keyPair = ECPair.fromWIF(privateKeyFrom, btcNetwork)
const p2wpkh = bitcoin.payments.p2wpkh({ pubkey: keyPair.publicKey, network: btcNetwork })
var scriptPubkey = p2wpkh.output.toString('hex');
console.log("////////////////////////////////////////////////////////////");
//const redeemScript = p2wpkh.redeem.output;
//var scriptPubkey2 = keyPair.publicKey;
//console.log(scriptPubkey);
//console.log(p2wpkh.pubkey.toString('hex'));
//console.log(p2wpkh.address);
//fee
var feePerByte = await btcFunctions.getFeePerByte();
var feeRate = feePerByte.regular * 100000000; //fee by byte on regular mode, APi provider blockchain.info
var txRef = await btcFunctions.getTxRef(unspentOutputs);
//var rawHex = await btcFunctions.getRawHex(txRef[0].tx_hash, network);
//console.log(balance);
//console.log(txRef);
//console.log(feePerByte);
console.log("////////////////////////////////////////////////////////////");
let utxoS = [];
if (txRef && txRef.length > 0) {
for (const tx of txRef) {
utxoS.push({
txHash: tx.tx_hash,
txIndex: tx.tx_output_n,
amount: tx.value * 100000000,
witnessUtxo: { script: Buffer.from(p2wpkh.output, 'hex'), value: tx.value * 100000000 },
// redeemScript: redeemScript
});
}
}
if (!utxoS.length) {
return;
}
var utxos = [];
var totalAmount = 0;
for (const utxo of utxoS) {
utxos.push({
txId: utxo.txHash,
vout: utxo.txIndex,
value: utxo.amount,
witnessUtxo: utxo.witnessUtxo,
});
//totalAmount += utxo.amount;
}
let targets = [
{
address: publicKeyTo,
value: amoutTosend * 100000000 // value in satoshi (0.5 BTC)
}
]
//console.log(amoutTosend * 100000000);
let { inputs, outputs, fee } = coinSelect(utxos, targets, feeRate)
console.log(fee);
if (!inputs || !outputs) return
const psbt = new bitcoin.Psbt({ network: btcNetwork });
inputs.forEach(input =>
psbt.addInput({
hash: input.txId,
index: input.vout,
witnessUtxo: input.witnessUtxo,
//privateKeyFrom: input.privateKeyFrom
})
)
outputs.forEach(output => {
if (!output.address) {
output.address = publicKeyFrom;
}
//console.log(output.value);
psbt.addOutput({
address: output.address,
value: output.value
});
})
psbt.signAllInputs(keyPair);
psbt.finalizeAllInputs();
const tx = psbt.extractTransaction(true);
const Signedtx = tx.toHex();
const txID = tx.getId();
console.log(Signedtx)
} else {
console.log("You do not have enough coin");
}
}
}
export default createTransactionTX;
please check if I am doing anything wrong I am a new bie
from coinselect.
Related Issues (20)
- TransactionBuilder is now deprecated HOT 5
- No inputs or outputs generated HOT 6
- Consider Output Address Types HOT 5
- Proposal For Segwit Update PR HOT 5
- PR #49 + npm HOT 1
- What is the best way to handle user selection of virtual bytes in coinselect? HOT 1
- BIP 125 selection for replacement HOT 2
- No solution found if many inputs HOT 3
- Can the coinSelect recognize that my utxos are from segwit? HOT 1
- inputs and outputs returning unidefined when pending balance HOT 5
- CoinSelect using multiple small UTXOs instead of one big HOT 3
- Segwit workaround safe to use? HOT 2
- "coinselect" always expose the largest UTXO no matter how small the payment is because it sorts by descending value. HOT 5
- Inputs nor outputs are returned when a certain condition is met HOT 4
- type error in typescript project HOT 1
- Is this project dead? HOT 1
- Check out trezor/trezor-suite/packages/utxo-lib/src/coinselect for any ideas HOT 1
- Reevaluating 'Dust' Considerations When Adding Change in Transactions HOT 5
- Library breaks with float feeRate
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coinselect.