Bitcoin Forum
April 26, 2024, 09:48:58 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: [HELP] Workflow of Bitcoin API  (Read 102 times)
night_driver (OP)
Newbie
*
Offline Offline

Activity: 13
Merit: 14


View Profile
June 19, 2022, 08:12:41 PM
Merited by NotATether (3), ABCbits (1), tadamichi (1)
 #1

Hello everyone,

I'm new in this forum and also in the bitcoin world.
I'm really happy to join this community that's why i have some questions.

I'm developper and i love discovering how bitcoin works in the technical part.

To do that i have installed the bitcoin software in a virtual machine and became a node at the same time  Grin

I have create some transactions on the testnet network and for the moment thats works nice BUT i'm sure that's what i did is really correct  Huh

So i would like to know if someone have some workflow/schemas to share that's explain all the interactions with methods to for example :
         - create a transaction
         - specify fees on a transaction
         - retrieve transactions with status for a specific address
     
By the way i also saw the "vout" fields when i call "listunspent" method but i don't know what it is. If someone can explain this please  Cheesy

Thanks you very much !
Have a nice day !
1714168138
Hero Member
*
Offline Offline

Posts: 1714168138

View Profile Personal Message (Offline)

Ignore
1714168138
Reply with quote  #2

1714168138
Report to moderator
"If you don't want people to know you're a scumbag then don't be a scumbag." -- margaritahuyan
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714168138
Hero Member
*
Offline Offline

Posts: 1714168138

View Profile Personal Message (Offline)

Ignore
1714168138
Reply with quote  #2

1714168138
Report to moderator
n0nce
Hero Member
*****
Offline Offline

Activity: 882
Merit: 5814


not your keys, not your coins!


View Profile WWW
June 19, 2022, 08:52:21 PM
Last edit: June 20, 2022, 11:48:40 AM by n0nce
Merited by dbshck (4), NeuroticFish (3), ABCbits (3)
 #2

Welcome to the forum!

So in general, when it comes to Bitcoin Core, it has really great help directly built-in into the command-line interface.
An example for your question about sending some Bitcoin (done through bitcoin-cli sendtoaddress):

Code:
~:% bitcoin-cli help sendtoaddress
sendtoaddress "address" amount ( "comment" "comment_to" subtractfeefromamount replaceable conf_target "estimate_mode" avoid_reuse fee_rate verbose )

Send an amount to a given address.
Requires wallet passphrase to be set with walletpassphrase call if wallet is encrypted.

Arguments:
1. address                  (string, required) The bitcoin address to send to.
2. amount                   (numeric or string, required) The amount in BTC to send. eg 0.1
3. comment                  (string, optional) A comment used to store what the transaction is for.
                            This is not part of the transaction, just kept in your wallet.
4. comment_to               (string, optional) A comment to store the name of the person or organization
                            to which you're sending the transaction. This is not part of the
                            transaction, just kept in your wallet.
5. subtractfeefromamount    (boolean, optional, default=false) The fee will be deducted from the amount being sent.
                            The recipient will receive less bitcoins than you enter in the amount field.
6. replaceable              (boolean, optional, default=wallet default) Allow this transaction to be replaced by a transaction with higher fees via BIP 125
7. conf_target              (numeric, optional, default=wallet -txconfirmtarget) Confirmation target in blocks
8. estimate_mode            (string, optional, default="unset") The fee estimate mode, must be one of (case insensitive):
                            "unset"
                            "economical"
                            "conservative"
9. avoid_reuse              (boolean, optional, default=true) (only available if avoid_reuse wallet flag is set) Avoid spending from dirty addresses; addresses are considered
                            dirty if they have previously been used in a transaction. If true, this also activates avoidpartialspends, grouping outputs by their addresses.
10. fee_rate                (numeric or string, optional, default=not set, fall back to wallet fee estimation) Specify a fee rate in sat/vB.
11. verbose                 (boolean, optional, default=false) If true, return extra information about the transaction.

Result (if verbose is not set or set to false):
"hex"    (string) The transaction id.

Result (if verbose is set to true):
{                          (json object)
  "txid" : "hex",          (string) The transaction id.
  "fee_reason" : "str"     (string) The transaction fee reason.
}

Examples:

Send 0.1 BTC
> bitcoin-cli sendtoaddress "bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl" 0.1

Send 0.1 BTC with a confirmation target of 6 blocks in economical fee estimate mode using positional arguments
> bitcoin-cli sendtoaddress "bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl" 0.1 "donation" "sean's outpost" false true 6 economical

Send 0.1 BTC with a fee rate of 1.1 sat/vB, subtract fee from amount, BIP125-replaceable, using positional arguments
> bitcoin-cli sendtoaddress "bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl" 0.1 "drinks" "room77" true true null "unset" null 1.1

Send 0.2 BTC with a confirmation target of 6 blocks in economical fee estimate mode using named arguments
> bitcoin-cli -named sendtoaddress address="bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl" amount=0.2 conf_target=6 estimate_mode="economical"

Send 0.5 BTC with a fee rate of 25 sat/vB using named arguments
> bitcoin-cli -named sendtoaddress address="bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl" amount=0.5 fee_rate=25
> bitcoin-cli -named sendtoaddress address="bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl" amount=0.5 fee_rate=25 subtractfeefromamount=false replaceable=true avoid_reuse=true comment="2 pizzas" comment_to="jeremy" verbose=true

You get a pretty thorough explanation and even some examples.

Regarding listunspent, the help is also pretty good. In short, vout is the index of an output in a transaction.
There are also good answers to this question with a quick web search:
A single Bitcoin transaction can have many outputs. The vout field lets you specify which output you want to spend.

Look at this transaction. Suppose you have the 1EZ5 key, but not the 199N key. You need to clarify to the Bitcoin network which output you want to spend.

Code:
~:% bitcoin-cli help listunspent
listunspent ( minconf maxconf ["address",...] include_unsafe query_options )

Returns array of unspent transaction outputs
with between minconf and maxconf (inclusive) confirmations.
Optionally filter to only include txouts paid to specified addresses.

Arguments:
1. minconf                            (numeric, optional, default=1) The minimum confirmations to filter
2. maxconf                            (numeric, optional, default=9999999) The maximum confirmations to filter
3. addresses                          (json array, optional, default=[]) The bitcoin addresses to filter
     [
       "address",                     (string) bitcoin address
       ...
     ]
4. include_unsafe                     (boolean, optional, default=true) Include outputs that are not safe to spend
                                      See description of "safe" attribute below.
5. query_options                      (json object, optional) JSON with query options
     {
       "minimumAmount": amount,       (numeric or string, optional, default="0.00") Minimum value of each UTXO in BTC
       "maximumAmount": amount,       (numeric or string, optional, default=unlimited) Maximum value of each UTXO in BTC
       "maximumCount": n,             (numeric, optional, default=unlimited) Maximum number of UTXOs
       "minimumSumAmount": amount,    (numeric or string, optional, default=unlimited) Minimum sum value of all UTXOs in BTC
     }

Result:
[                                (json array)
  {                              (json object)
    "txid" : "hex",              (string) the transaction id
    "vout" : n,                  (numeric) the vout value
    "address" : "str",           (string, optional) the bitcoin address
    "label" : "str",             (string, optional) The associated label, or "" for the default label
    "scriptPubKey" : "str",      (string) the script key
    "amount" : n,                (numeric) the transaction output amount in BTC
    "confirmations" : n,         (numeric) The number of confirmations
    "ancestorcount" : n,         (numeric, optional) The number of in-mempool ancestor transactions, including this one (if transaction is in the mempool)
    "ancestorsize" : n,          (numeric, optional) The virtual transaction size of in-mempool ancestors, including this one (if transaction is in the mempool)
    "ancestorfees" : n,          (numeric, optional) The total fees of in-mempool ancestors (including this one) with fee deltas used for mining priority in sat (if transaction is in the mempool)
    "redeemScript" : "hex",      (string, optional) The redeemScript if scriptPubKey is P2SH
    "witnessScript" : "str",     (string, optional) witnessScript if the scriptPubKey is P2WSH or P2SH-P2WSH
    "spendable" : true|false,    (boolean) Whether we have the private keys to spend this output
    "solvable" : true|false,     (boolean) Whether we know how to spend this output, ignoring the lack of keys
    "reused" : true|false,       (boolean, optional) (only present if avoid_reuse is set) Whether this output is reused/dirty (sent to an address that was previously spent from)
    "desc" : "str",              (string, optional) (only when solvable) A descriptor for spending this output
    "safe" : true|false          (boolean) Whether this output is considered safe to spend. Unconfirmed transactions
                                 from outside keys and unconfirmed replacement transactions are considered unsafe
                                 and are not eligible for spending by fundrawtransaction and sendtoaddress.
  },
  ...
]

Examples:
> bitcoin-cli listunspent
> bitcoin-cli listunspent 6 9999999 "[\"bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl\",\"bc1q02ad21edsxd23d32dfgqqsz4vv4nmtfzuklhy3\"]"
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "listunspent", "params": [6, 9999999 "[\"bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl\",\"bc1q02ad21edsxd23d32dfgqqsz4vv4nmtfzuklhy3\"]"]}' -H 'content-type: text/plain;' http://127.0.0.1:8332/
> bitcoin-cli listunspent 6 9999999 '[]' true '{ "minimumAmount": 0.005 }'
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "listunspent", "params": [6, 9999999, [] , true, { "minimumAmount": 0.005 } ]}' -H 'content-type: text/plain;' http://127.0.0.1:8332/

To retreive transactions for a given address, use listreceivedbyaddress.
Edit: I myself didn't read the help section of this command, even though I posted it below. I leave it for the interested reader.
There is no RPC call to get transactions for a given address, now that I scroll through the various commands' help pages, but you will probably need listtransactions and filter by address yourself.

Code:
~:% bitcoin-cli help listreceivedbyaddress
listreceivedbyaddress ( minconf include_empty include_watchonly "address_filter" include_immature_coinbase )

List balances by receiving address.

Arguments:
1. minconf                      (numeric, optional, default=1) The minimum number of confirmations before payments are included.
2. include_empty                (boolean, optional, default=false) Whether to include addresses that haven't received any payments.
3. include_watchonly            (boolean, optional, default=true for watch-only wallets, otherwise false) Whether to include watch-only addresses (see 'importaddress')
4. address_filter               (string, optional) If present and non-empty, only return information on this address.
5. include_immature_coinbase    (boolean, optional, default=false) Include immature coinbase transactions.

Result:
[                                        (json array)
  {                                      (json object)
    "involvesWatchonly" : true|false,    (boolean, optional) Only returns true if imported addresses were involved in transaction
    "address" : "str",                   (string) The receiving address
    "amount" : n,                        (numeric) The total amount in BTC received by the address
    "confirmations" : n,                 (numeric) The number of confirmations of the most recent transaction included
    "label" : "str",                     (string) The label of the receiving address. The default label is ""
    "txids" : [                          (json array)
      "hex",                             (string) The ids of transactions received with the address
      ...
    ]
  },
  ...
]

Examples:
> bitcoin-cli listreceivedbyaddress
> bitcoin-cli listreceivedbyaddress 6 true
> bitcoin-cli listreceivedbyaddress 6 true true "" true
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "listreceivedbyaddress", "params": [6, true, true]}' -H 'content-type: text/plain;' http://127.0.0.1:8332/
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "listreceivedbyaddress", "params": [6, true, true, "bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl", true]}' -H 'content-type: text/plain;' http://127.0.0.1:8332/



In general, if you're looking to do something in Bitcoin Core, just call bitcoin-cli help, scroll through and find what makes most sense. For more details and more help, use bitcoin-cli help X (where X is the command in question), like I've shown above.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
nc50lc
Legendary
*
Offline Offline

Activity: 2394
Merit: 5538


Self-proclaimed Genius


View Profile
June 20, 2022, 04:37:55 AM
Merited by ABCbits (1), tadamichi (1)
 #3

I'm developper and i love discovering how bitcoin works in the technical part.
You can start with the developer guides, here: https://developer.bitcoin.org/devguide/index.html
Mostly based from the reference client: Bitcoin Core.

By the way i also saw the "vout" fields when i call "listunspent" method but i don't know what it is. If someone can explain this please  Cheesy
Terms such as "vout" are described in the Glossary, under the Table of Contents.

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
NotATether
Legendary
*
Offline Offline

Activity: 1582
Merit: 6687


bitcoincleanup.com / bitmixlist.org


View Profile WWW
June 20, 2022, 11:14:27 AM
Merited by ABCbits (2), n0nce (1)
 #4

I have create some transactions on the testnet network and for the moment thats works nice BUT i'm sure that's what i did is really correct  Huh

So i would like to know if someone have some workflow/schemas to share that's explain all the interactions with methods to for example :
         - create a transaction
         - specify fees on a transaction
         - retrieve transactions with status for a specific address

The first two actions are done in the same RPC call send and also in the window of Bitcoin-QT that lets you create transactions. (Beware that the fees are specified in the RPC call as sats/kilobytes!)

The last action is accomplished by either calling listtransactions on the wallet or subscribing to the ZeroMQ channels published by Bitcoin Core and then filtering out the transactions to addresses in your wallet. The last method needs you to run Bitcoin Core with -zmqpubrawtx=<ipaddress-on-your-pc:port> argument, and can be run as localhost, for example.

Quote
By the way i also saw the "vout" fields when i call "listunspent" method but i don't know what it is. If someone can explain this please  Cheesy

"vout" is the index number used to identify an output inside a transaction.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!