Bitcoin原始API

Bitcoin Core APIs

Remote Procedure Calls (RPCs)

Warning: the block chain and memory pool can include arbitrary data which several of the commands below will return in hex format. If you convert this data to another format in an executable context, it could be used in an exploit. For example, displaying an output script as ASCII text in a webpage could add arbitrary Javascript to that page and create a cross-site scripting (XSS) exploit. To avoid problems, please treat block chain and memory pool data as an arbitrary input from an untrusted source.

addmultisigaddress

addmultisigaddress   [account]

Add a P2SH multisig address to the wallet.

Related RPCs: createmultisig

Argument #1: Number Of Signatures Required

Number; required: the minimum (m) number of signatures required to spend satoshis sent to this m-of-n P2SH multisig script.


Argument #2: Full Public Keys, Or Addresses For Known Public Keys

String; required: A JSON array of hex-encoded public keys or addresses for public keys known to this Bitcoin Core instance. The multisig script can only use full (unhashed) public keys, so you generally must provide public keys for any address not known to this wallet.

[
  ""
  ,[...]
]

Argument #3: Account Name

String; optional: The name of an account in the wallet which will store the address.

""

Result: A P2SH Address Printed And Stored In The Wallet

String: a hash of the P2SH multisig redeemScript, which is also stored in the wallet so Bitcoin Core can monitor the network and block chain for transactions sent to that address (which will be displayed in the wallet as spendable balances).

Example

Adding a 2-of-3 P2SH multisig address to the “test account” by mixing two P2PKH addresses and one full public key:

> bitcoin-cli -testnet addmultisigaddress \
  2 \
  '''
    [ 
      "mjbLRSidW1MY8oubvs4SMEnHNFXxCcoehQ", 
      "02ecd2d250a76d204011de6bc365a56033b9b3a149f679bc17205555d3c2b2854f", 
      "mt17cV37fBqZsnMmrHnGCm9pM28R1kQdMG" 
    ]
  ''' \
  'test account'

Result:

2MyVxxgNBk5zHRPRY2iVjGRJHYZEp1pMCSq

(New P2SH multisig address also stored in wallet.)

addnode

addnode : 

Attempts add or remove a node from the addnode list, or try a connection to a node once.

Argument #1: IP Address And Port Of Node

String, required: the colon-delimited IP address and port of the node to add, remove, or connect to.

Argument #2: Add Or Remove The Node, Or Try Once To Connect

String, required: whether to add or remove the node to the list of known nodes. This does not necessarily mean that a connection to the node will be established. To attempt to establish a connection immediately, use onetry.

Return: Empty Or Error

Will not return any data if the node is added or if onetry is used (even if the connection attempt fails). Will return an error if you try removing an unknown node.

Example

Try connecting to the following node.

> bitcoin-cli -testnet addnode 68.39.150.9:18333 onetry

backupwallet

backupwallet 

Safely copies wallet.dat to destination, which can be a directory or a path with filename.

Argument #1: Destination Directory Or Filename

String, required: a directory or filename. If a directory, a file named wallet.dat will be created or overwritten. If a filename, a file of that name will be created or overwritten.

Return: Empty Or Error

Nothing will be returned on success. If the file couldn’t be created or written, an error will be returned.

Example

> bitcoin-cli -testnet backupwallet /tmp/backup.dat

createmultisig

createmultisig  

Creates a multi-signature address.

Related RPCs: addmultisigaddress

Argument #1: Number Of Signatures Required

Number; required: the minimum (m) number of signatures required to spend satoshis sent to this m-of-n multisig script.


Argument #2: Full Public Keys, Or Addresses For Known Public Keys

String; required: A JSON array of hex-encoded public keys or addresses for public keys known to this Bitcoin Core instance. The multisig script can only use full (unhashed) public keys, so you generally must provide public keys for any address not known to this wallet.

[
  ""
  ,[...]
]

Result: Address And Hex-Encoded RedeemScript

String: JSON object with the P2SH address and hex-encoded redeemScript.

{
  "address":"",
  "redeemScript":""
}

Example

Creating a 2-of-3 P2SH multisig address by mixing two P2PKH addresses and one full public key:

> bitcoin-cli -testnet createmultisig 2 '''
  [ 
    "mjbLRSidW1MY8oubvs4SMEnHNFXxCcoehQ", 
    "02ecd2d250a76d204011de6bc365a56033b9b3a149f679bc17205555d3c2b2854f", 
    "mt17cV37fBqZsnMmrHnGCm9pM28R1kQdMG" 
  ]
  '''

Result (redeemScript wrapped):

{
  "address" : "2MyVxxgNBk5zHRPRY2iVjGRJHYZEp1pMCSq",
  "redeemScript" : "522103ede722780d27b05f0b1169efc90fa15a601a32\
                    fc6c3295114500c586831b6aaf2102ecd2d250a76d20\
                    4011de6bc365a56033b9b3a149f679bc17205555d3c2\
                    b2854f21022d609d2f0d359e5bc0e5d0ea20ff9f5d33\
                    96cb5b1906aa9c56a0e7b5edc0c5d553ae"
}

createrawtransaction

createrawtransaction  

Create an unsigned transaction in hex rawtransaction format that spends a previous output to an new output with a P2PKH or P2SH address. The transaction is not stored in the wallet or transmitted to the network.

Argument #1: References To Previous Outputs

String; required: A JSON array of JSON objects. Each object in the array references a previous output by its txid (string; required) and output index number, called vout (number; required).

[
  {
    "txid":"",
    "vout":
  }
  ,[...]
]

Argument #2: P2PKH Or P2SH Addresses For New Outputs

String; required: A JSON object with P2PKH or P2SH addresses to pay as keys and the amount to pay each address as its value (number; required) in decimal bitcoins.

{
  "
": . ,[...] }

Result: Unsigned Raw Transaction (In Hex)

String: The resulting unsigned transaction in hex-encoded rawtransaction format, or a JSON error if any value provided was invalid.

Example

> bitcoin-cli -testnet createrawtransaction '''
  [
    { 
      "txid":"5a7d24cd665108c66b2d56146f244932edae4e2376b561b3d396d5ae017b9589", 
      "vout":0 
    } 
  ]
  ''' '''
  { 
    "mgnucj8nYqdrPFh2JfZSB1NmUThUGnmsqe": 0.1 
  }
''''

Result:

010000000189957b01aed596d3b361b576234eaeed3249246f14562d6bc60851\
66cd247d5a0000000000ffffffff0180969800000000001976a9140dfc8bafc8\
419853b34d5e072ad37d1a5159f58488ac00000000

decoderawtransaction

decoderawtransaction 

Decode a rawtransaction format hex string into a JSON object representing the transaction.

Argument: RawTransaction Hex

String; required: a complete transaction in rawtransaction format hex.

Result: JSON Object

A JSON object describing the the transaction is returned. The object is described in parts below.

{
  "txid" : "",
  "version" : ,
  "locktime" : ,

The transaction identifier (txid), the transaction version number, and the locktime.

  "vin" : [
     {
       "txid": "",
       "vout": ,
       "scriptSig": {
         "asm": "
                    
                    

你可能感兴趣的:(bitcoin学习)