My target - send to one of my users requested amount of BTC. I have many BTC wallets generated from the same mnemonic phrase with different balances.
So, my inputs data is - target wallet, target amount and list of wallets with balances. If found a set of inputs with total balance more than I need to send, I need to return difference between inputs balance and target amount to random input.
My data looks like:
[
{
"wallet": "xxxx1",
"privateKey": "key1",
"unspentAmount": 46659,
"unspentTransactions": [
{
"tx_hash_big_endian": "..",
"tx_hash": "...",
"tx_output_n": 0,
"script": "...",
"value": 46659,
"value_hex": "00b643",
"confirmations": 757,
"tx_index": 1156017252431081
}
]
},
{
"wallet": "xxx2",
"privateKey": "key2",
"unspentAmount": 13339,
"unspentTransactions": [
{
"tx_hash_big_endian": "...",
"tx_hash": "...",
"tx_output_n": 0,
"script": "...",
"value": 13339,
"value_hex": "00b643",
"confirmations": 757,
"tx_index": 1156017252431081
}
]
}
]
How to build transaction using bitcoin-core or bitcoin-lib? I need multiple inputs and multiple outputs.