ExBitcoin v0.4.0 ExBitcoin.Elixir.Tx View Source
Raw transaction related RPC
Link to this section Summary
Functions
combinerawtransaction [“hexstring”,…]
createrawtransaction [{“txid”:”id”,”vout”:n},…] {“address”:amount,”data”:”hex”,…} ( locktime ) ( replaceable )
decoderawtransaction “hexstring”
decodescript “hexstring”
fundrawtransaction “hexstring” ( options )
getrawtransaction “txid” ( verbose )
sendrawtransaction “hexstring” ( allowhighfees )
signrawtransaction “hexstring” ( [{“txid”:”id”,”vout”:n,”scriptPubKey”:”hex”,”redeemScript”:”hex”},…] [“privatekey1”,…] sighashtype )
Link to this section Functions
combinerawtransaction(:"String.t") :: any()
combinerawtransaction [“hexstring”,…]
Combine multiple partially signed transactions into one transaction. The combined transaction may be another partially signed transaction or a fully signed transaction. Arguments:
- “txs” (string) A json array of hex strings of partially signed transactions [ “hexstring” (string) A transaction hash ,… ]
Result: “hex” (string) The hex-encoded raw transaction with signature(s)
Examples:
bitcoin-cli combinerawtransaction [“myhex1”, “myhex2”, “myhex3”]
createrawtransaction(:"String.t", :"String.t", :"String.t", :"String.t") :: any()
createrawtransaction [{“txid”:”id”,”vout”:n},…] {“address”:amount,”data”:”hex”,…} ( locktime ) ( replaceable )
Create a transaction spending the given inputs and creating new outputs. Outputs can be addresses or data. Returns hex-encoded raw transaction. Note that the transaction’s inputs are not signed, and it is not stored in the wallet or transmitted to the network.
Arguments:
“inputs” (array, required) A json array of json objects [ {
"txid":"id", (string, required) The transaction id "vout":n, (numeric, required) The output number "sequence":n (numeric, optional) The sequence number
} ,… ]
- “outputs” (object, required) a json object with outputs { “address”: x.xxx, (numeric or string, required) The key is the bitcoin address, the numeric value (can be string) is the BTC amount “data”: “hex” (string, required) The key is “data”, the value is hex encoded data ,… }
- locktime (numeric, optional, default=0) Raw locktime. Non-0 value also locktime-activates inputs
- replaceable (boolean, optional, default=false) Marks this transaction as BIP125 replaceable. Allows this transaction to be replaced by a transaction with higher fees. If provided, it is an error if explicit sequence numbers are incompatible.
Result: “transaction” (string) hex string of the transaction
Examples:
bitcoin-cli createrawtransaction “[{\”txid\”:\”myid\”,\”vout\”:0}]” “{\”address\”:0.01}” bitcoin-cli createrawtransaction “[{\”txid\”:\”myid\”,\”vout\”:0}]” “{\”data\”:\”00010203\”}” curl —user myusername —data-binary ‘{“jsonrpc”: “1.0”, “id”:”curltest”, “method”: “createrawtransaction”, “params”: [“[{\”txid\”:\”myid\”,\”vout\”:0}]”, “{\”address\”:0.01}”] }’ -H ‘content-type: text/plain;’ http://127.0.0.1:8332/ curl —user myusername —data-binary ‘{“jsonrpc”: “1.0”, “id”:”curltest”, “method”: “createrawtransaction”, “params”: [“[{\”txid\”:\”myid\”,\”vout\”:0}]”, “{\”data\”:\”00010203\”}”] }’ -H ‘content-type: text/plain;’ http://127.0.0.1:8332/
decoderawtransaction(:"String.t") :: any()
decoderawtransaction “hexstring”
Return a JSON object representing the serialized, hex-encoded transaction.
Arguments:
- “hexstring” (string, required) The transaction hex string
Result: { “txid” : “id”, (string) The transaction id “hash” : “id”, (string) The transaction hash (differs from txid for witness transactions) “size” : n, (numeric) The transaction size “vsize” : n, (numeric) The virtual transaction size (differs from size for witness transactions) “version” : n, (numeric) The version “locktime” : ttt, (numeric) The lock time “vin” : [ (array of json objects)
{
"txid": "id", (string) The transaction id
"vout": n, (numeric) The output number
"scriptSig": { (json object) The script
"asm": "asm", (string) asm
"hex": "hex" (string) hex
},
"txinwitness": ["hex", ...] (array of string) hex-encoded witness data (if any)
"sequence": n (numeric) The script sequence number
}
,...
], “vout” : [ (array of json objects)
{
"value" : x.xxx, (numeric) The value in BTC
"n" : n, (numeric) index
"scriptPubKey" : { (json object)
"asm" : "asm", (string) the asm
"hex" : "hex", (string) the hex
"reqSigs" : n, (numeric) The required sigs
"type" : "pubkeyhash", (string) The type, eg 'pubkeyhash'
"addresses" : [ (json array of string)
"12tvKAXCxZjSmdNbao16dKXC8tRWfcF5oc" (string) bitcoin address
,...
]
}
}
,...
], }
Examples:
bitcoin-cli decoderawtransaction “hexstring” curl —user myusername —data-binary ‘{“jsonrpc”: “1.0”, “id”:”curltest”, “method”: “decoderawtransaction”, “params”: [“hexstring”] }’ -H ‘content-type: text/plain;’ http://127.0.0.1:8332/
decodescript “hexstring”
Decode a hex-encoded script.
Arguments:
- “hexstring” (string) the hex encoded script
Result: { “asm”:”asm”, (string) Script public key “hex”:”hex”, (string) hex encoded public key “type”:”type”, (string) The output type “reqSigs”: n, (numeric) The required signatures “addresses”: [ (json array of string)
"address" (string) bitcoin address
,...
], “p2sh”,”address” (string) address of P2SH script wrapping this redeem script (not returned if the script is already a P2SH). }
Examples:
bitcoin-cli decodescript “hexstring” curl —user myusername —data-binary ‘{“jsonrpc”: “1.0”, “id”:”curltest”, “method”: “decodescript”, “params”: [“hexstring”] }’ -H ‘content-type: text/plain;’ http://127.0.0.1:8332/
fundrawtransaction(:"String.t", :"String.t") :: any()
fundrawtransaction “hexstring” ( options )
Add inputs to a transaction until it has enough in value to meet its out value. This will not modify existing inputs, and will add at most one change output to the outputs. No existing outputs will be modified unless “subtractFeeFromOutputs” is specified. Note that inputs which were signed may need to be resigned after completion since in/outputs have been added. The inputs added will not be signed, use signrawtransaction for that. Note that all existing inputs must have their previous output transaction be in the wallet. Note that all inputs selected must be of standard form and P2SH scripts must be in the wallet using importaddress or addmultisigaddress (to calculate fees). You can see whether this is the case by checking the “solvable” field in the listunspent output. Only pay-to-pubkey, multisig, and P2SH versions thereof are currently supported for watch-only
Arguments:
- “hexstring” (string, required) The hex string of the raw transaction
options (object, optional) { “changeAddress” (string, optional, default pool address) The bitcoin address to receive the change “changePosition” (numeric, optional, default random) The index of the change output “includeWatching” (boolean, optional, default false) Also select inputs which are watch only “lockUnspents” (boolean, optional, default false) Lock selected unspent outputs “feeRate” (numeric, optional, default not set: makes wallet determine the fee) Set a specific feerate (BTC per KB) “subtractFeeFromOutputs” (array, optional) A json array of integers.
The fee will be equally deducted from the amount of each specified output. The outputs are specified by their zero-based index, before any change output is added. Those recipients will receive less bitcoins than you enter in their corresponding amount field. If no outputs are specified here, the sender pays the fee. [vout_index,...]
“replaceable” (boolean, optional) Marks this transaction as BIP125 replaceable.
Allows this transaction to be replaced by a transaction with higher fees
“conf_target” (numeric, optional) Confirmation target (in blocks) “estimate_mode” (string, optional, default=UNSET) The fee estimate mode, must be one of:
"UNSET" "ECONOMICAL" "CONSERVATIVE"
}
for backward compatibility: passing in a true instead of an object will result in {"includeWatching":true}
Result: { “hex”: “value”, (string) The resulting raw transaction (hex-encoded string) “fee”: n, (numeric) Fee in BTC the resulting transaction pays “changepos”: n (numeric) The position of the added change output, or -1 }
Examples:
Create a transaction with no inputs
bitcoin-cli createrawtransaction “[]” “{\”myaddress\”:0.01}”
Add sufficient unsigned inputs to meet the output value
bitcoin-cli fundrawtransaction “rawtransactionhex”
Sign the transaction
bitcoin-cli signrawtransaction “fundedtransactionhex”
Send the transaction
bitcoin-cli sendrawtransaction “signedtransactionhex”
getrawtransaction(:"String.t", :"String.t") :: any()
getrawtransaction “txid” ( verbose )
NOTE: By default this function only works for mempool transactions. If the -txindex option is enabled, it also works for blockchain transactions. DEPRECATED: for now, it also works for transactions with unspent outputs.
Return the raw transaction data.
If verbose is ‘true’, returns an Object with information about ‘txid’. If verbose is ‘false’ or omitted, returns a string that is serialized, hex-encoded data for ‘txid’.
Arguments:
- “txid” (string, required) The transaction id
- verbose (bool, optional, default=false) If false, return a string, otherwise return a json object
Result (if verbose is not set or set to false): “data” (string) The serialized, hex-encoded data for ‘txid’
Result (if verbose is set to true): { “hex” : “data”, (string) The serialized, hex-encoded data for ‘txid’ “txid” : “id”, (string) The transaction id (same as provided) “hash” : “id”, (string) The transaction hash (differs from txid for witness transactions) “size” : n, (numeric) The serialized transaction size “vsize” : n, (numeric) The virtual transaction size (differs from size for witness transactions) “version” : n, (numeric) The version “locktime” : ttt, (numeric) The lock time “vin” : [ (array of json objects)
{
"txid": "id", (string) The transaction id
"vout": n, (numeric)
"scriptSig": { (json object) The script
"asm": "asm", (string) asm
"hex": "hex" (string) hex
},
"sequence": n (numeric) The script sequence number
"txinwitness": ["hex", ...] (array of string) hex-encoded witness data (if any)
}
,...
], “vout” : [ (array of json objects)
{
"value" : x.xxx, (numeric) The value in BTC
"n" : n, (numeric) index
"scriptPubKey" : { (json object)
"asm" : "asm", (string) the asm
"hex" : "hex", (string) the hex
"reqSigs" : n, (numeric) The required sigs
"type" : "pubkeyhash", (string) The type, eg 'pubkeyhash'
"addresses" : [ (json array of string)
"address" (string) bitcoin address
,...
]
}
}
,...
], “blockhash” : “hash”, (string) the block hash “confirmations” : n, (numeric) The confirmations “time” : ttt, (numeric) The transaction time in seconds since epoch (Jan 1 1970 GMT) “blocktime” : ttt (numeric) The block time in seconds since epoch (Jan 1 1970 GMT) }
Examples:
bitcoin-cli getrawtransaction “mytxid” bitcoin-cli getrawtransaction “mytxid” true curl —user myusername —data-binary ‘{“jsonrpc”: “1.0”, “id”:”curltest”, “method”: “getrawtransaction”, “params”: [“mytxid”, true] }’ -H ‘content-type: text/plain;’ http://127.0.0.1:8332/
sendrawtransaction(:"String.t", :"String.t") :: any()
sendrawtransaction “hexstring” ( allowhighfees )
Submits raw transaction (serialized, hex-encoded) to local node and network.
Also see createrawtransaction and signrawtransaction calls.
Arguments:
- “hexstring” (string, required) The hex string of the raw transaction)
- allowhighfees (boolean, optional, default=false) Allow high fees
Result: “hex” (string) The transaction hash in hex
Examples:
Create a transaction
bitcoin-cli createrawtransaction “[{\”txid\” : \”mytxid\”,\”vout\”:0}]” “{\”myaddress\”:0.01}” Sign the transaction, and get back the hex bitcoin-cli signrawtransaction “myhex”
Send the transaction (signed hex)
bitcoin-cli sendrawtransaction “signedhex”
As a json rpc call
curl —user myusername —data-binary ‘{“jsonrpc”: “1.0”, “id”:”curltest”, “method”: “sendrawtransaction”, “params”: [“signedhex”] }’ -H ‘content-type: text/plain;’ http://127.0.0.1:8332/
signrawtransaction(:"String.t", :"String.t", :"String.t", :"String.t") :: any()
signrawtransaction “hexstring” ( [{“txid”:”id”,”vout”:n,”scriptPubKey”:”hex”,”redeemScript”:”hex”},…] [“privatekey1”,…] sighashtype )
Sign inputs for raw transaction (serialized, hex-encoded). The second optional argument (may be null) is an array of previous transaction outputs that this transaction depends on but may not yet be in the block chain. The third optional argument (may be null) is an array of base58-encoded private keys that, if given, will be the only keys used to sign the transaction.
Arguments:
- “hexstring” (string, required) The transaction hex string
“prevtxs” (string, optional) An json array of previous dependent transaction outputs [ (json array of json objects, or ‘null’ if none provided) {
"txid":"id", (string, required) The transaction id "vout":n, (numeric, required) The output number "scriptPubKey": "hex", (string, required) script key "redeemScript": "hex", (string, required for P2SH or P2WSH) redeem script "amount": value (numeric, required) The amount spent
} ,… ]
- “privkeys” (string, optional) A json array of base58-encoded private keys for signing [ (json array of strings, or ‘null’ if none provided) “privatekey” (string) private key in base58-encoding ,… ]
- “sighashtype” (string, optional, default=ALL) The signature hash type. Must be one of “ALL” “NONE” “SINGLE” “ALL|ANYONECANPAY” “NONE|ANYONECANPAY” “SINGLE|ANYONECANPAY”
Result: { “hex” : “value”, (string) The hex-encoded raw transaction with signature(s) “complete” : true|false, (boolean) If the transaction has a complete set of signatures “errors” : [ (json array of objects) Script verification errors (if there are any)
{
"txid" : "hash", (string) The hash of the referenced, previous transaction
"vout" : n, (numeric) The index of the output to spent and used as input
"scriptSig" : "hex", (string) The hex-encoded signature script
"sequence" : n, (numeric) Script sequence number
"error" : "text" (string) Verification or signing error related to the input
}
,...
] }
Examples:
bitcoin-cli signrawtransaction “myhex” curl —user myusername —data-binary ‘{“jsonrpc”: “1.0”, “id”:”curltest”, “method”: “signrawtransaction”, “params”: [“myhex”] }’ -H ‘content-type: text/plain;’ http://127.0.0.1:8332/