ExBitcoin v0.4.0 ExBitcoin.Util View Source
utility functions
Link to this section Summary
Functions
createmultisig nrequired [“key”,…]
estimatefee nblocks
estimatesmartfee conf_target (“estimate_mode”)
signmessagewithprivkey “privkey” “message”
validateaddress “address”
verifymessage “address” “signature” “message”
Link to this section Functions
createmultisig(:"String.t", :"String.t") :: any()
createmultisig nrequired [“key”,…]
Creates a multi-signature address with n signature of m keys required. It returns a json object with the address and redeemScript.
Arguments:
- nrequired (numeric, required) The number of required signatures out of the n keys or addresses.
- “keys” (string, required) A json array of keys which are bitcoin addresses or hex-encoded public keys [ “key” (string) bitcoin address or hex-encoded public key ,… ]
Result: { “address”:”multisigaddress”, (string) The value of the new multisig address. “redeemScript”:”script” (string) The string value of the hex-encoded redemption script. }
Examples:
Create a multisig address from 2 addresses
bitcoin-cli createmultisig 2 “[\”16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\”,\”171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\”]”
As a json rpc call
curl —user myusername —data-binary ‘{“jsonrpc”: “1.0”, “id”:”curltest”, “method”: “createmultisig”, “params”: [2, “[\”16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\”,\”171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\”]”] }’ -H ‘content-type: text/plain;’ http://127.0.0.1:8332/
estimatefee nblocks
DEPRECATED. Please use estimatesmartfee for more intelligent estimates. Estimates the approximate fee per kilobyte needed for a transaction to begin confirmation within nblocks blocks. Uses virtual transaction size of transaction as defined in BIP 141 (witness data is discounted).
Arguments:
- nblocks (numeric, required)
Result: n (numeric) estimated fee-per-kilobyte
A negative value is returned if not enough transactions and blocks have been observed to make an estimate. -1 is always returned for nblocks == 1 as it is impossible to calculate a fee that is high enough to get reliably included in the next block.
Example:
bitcoin-cli estimatefee 6
estimatesmartfee(:"String.t", :"String.t") :: any()
estimatesmartfee conf_target (“estimate_mode”)
Estimates the approximate fee per kilobyte needed for a transaction to begin confirmation within conf_target blocks if possible and return the number of blocks for which the estimate is valid. Uses virtual transaction size as defined in BIP 141 (witness data is discounted).
Arguments:
- conf_target (numeric) Confirmation target in blocks (1 - 1008)
“estimate_mode” (string, optional, default=CONSERVATIVE) The fee estimate mode.
Whether to return a more conservative estimate which also satisfies a longer history. A conservative estimate potentially returns a higher feerate and is more likely to be sufficient for the desired target, but is not as responsive to short term drops in the prevailing fee market. Must be one of:
“UNSET” (defaults to CONSERVATIVE) “ECONOMICAL” “CONSERVATIVE”
Result: { “feerate” : x.x, (numeric, optional) estimate fee-per-kilobyte (in BTC) “errors”: [ str… ] (json array of strings, optional) Errors encountered during processing “blocks” : n (numeric) block number where estimate was found }
The request target will be clamped between 2 and the highest target fee estimation is able to return based on how long it has been running. An error is returned if not enough transactions and blocks have been observed to make an estimate for any number of blocks.
Example:
bitcoin-cli estimatesmartfee 6
signmessagewithprivkey(:"String.t", :"String.t") :: any()
signmessagewithprivkey “privkey” “message”
Sign a message with the private key of an address
Arguments:
- “privkey” (string, required) The private key to sign the message with.
- “message” (string, required) The message to create a signature of.
Result: “signature” (string) The signature of the message encoded in base 64
Examples:
Create the signature
bitcoin-cli signmessagewithprivkey “privkey” “my message”
Verify the signature
bitcoin-cli verifymessage “1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX” “signature” “my message”
As json rpc
curl —user myusername —data-binary ‘{“jsonrpc”: “1.0”, “id”:”curltest”, “method”: “signmessagewithprivkey”, “params”: [“privkey”, “my message”] }’ -H ‘content-type: text/plain;’ http://127.0.0.1:8332/
validateaddress “address”
Return information about the given bitcoin address.
Arguments:
- “address” (string, required) The bitcoin address to validate
Result: { “isvalid” : true|false, (boolean) If the address is valid or not. If not, this is the only property returned. “address” : “address”, (string) The bitcoin address validated “scriptPubKey” : “hex”, (string) The hex encoded scriptPubKey generated by the address “ismine” : true|false, (boolean) If the address is yours or not “iswatchonly” : true|false, (boolean) If the address is watchonly “isscript” : true|false, (boolean) If the key is a script “script” : “type” (string, optional) The output script type. Possible types: nonstandard, pubkey, pubkeyhash, scripthash, multisig, nulldata, witness_v0_keyhash, witness_v0_scripthash “hex” : “hex”, (string, optional) The redeemscript for the p2sh address “addresses” (string, optional) Array of addresses associated with the known redeemscript
[
"address"
,...
]
“sigsrequired” : xxxxx (numeric, optional) Number of signatures required to spend multisig output
“pubkey” : “publickeyhex”, (string) The hex value of the raw public key
“iscompressed” : true|false, (boolean) If the address is compressed
“account” : “account” (string) DEPRECATED. The account associated with the address, “” is the default account
“timestamp” : timestamp, (number, optional) The creation time of the key if available in seconds since epoch (Jan 1 1970 GMT)
“hdkeypath” : “keypath” (string, optional) The HD keypath if the key is HD and available
“hdmasterkeyid” : “
Examples:
bitcoin-cli validateaddress “1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc” curl —user myusername —data-binary ‘{“jsonrpc”: “1.0”, “id”:”curltest”, “method”: “validateaddress”, “params”: [“1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc”] }’ -H ‘content-type: text/plain;’ http://127.0.0.1:8332/
verifymessage(:"String.t", :"String.t", :"String.t") :: any()
verifymessage “address” “signature” “message”
Verify a signed message
Arguments:
- “address” (string, required) The bitcoin address to use for the signature.
- “signature” (string, required) The signature provided by the signer in base 64 encoding (see signmessage).
- “message” (string, required) The message that was signed.
Result: true|false (boolean) If the signature is verified or not.
Examples:
Unlock the wallet for 30 seconds
bitcoin-cli walletpassphrase “mypassphrase” 30
Create the signature
bitcoin-cli signmessage “1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX” “my message”
Verify the signature
bitcoin-cli verifymessage “1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX” “signature” “my message”
As json rpc
curl —user myusername —data-binary ‘{“jsonrpc”: “1.0”, “id”:”curltest”, “method”: “verifymessage”, “params”: [“1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX”, “signature”, “my message”] }’ -H ‘content-type: text/plain;’ http://127.0.0.1:8332/