Skip to content

Implement Bitcoin JSON RPC Methods #3

@shekohex

Description

@shekohex

Bitcoin Core RPC Methods

Here is a list of Methods that provided on bitcoin core
all of them will be auto-generated for us
with a bit small amount of work

Wanna Help ?

  1. Fork & Clone it in your local machine
  2. Chose a Method From Above, and you should check if there is no PR created for it.
  3. Create a new branch, the branch name should be in this format bitclient-{methodname}
  4. Add the Method to a new json file named after the method name in src/methods See below.
  5. Create a PR with (feat): Adding {methodname} to Bitclient
  6. after adding it and your PR has been accepted, kindly delete your branch and rebase.
  7. Thank you ❤️

How To Add Methods

the structure of json file is really simple, here is an example of getaccount method

  "getAccount": {
    "description": "The getaccount RPC returns the name of the account associated with the given address.",
    "spec": "https://bitcoin.org/en/developer-reference#getaccount",
    "params": {
      "address": {
        "type": "string",
        "required": true,
        "description": "A P2PKH or P2SH Bitcoin address belonging either to a specific account or the default account (“”)"
      }
    },
    "result": {
      "type": "string",
      "required": true,
      "description": "The name of an account, or an empty string (“”, the default account)"
    }
  }

all information has been copied from the method reference.

but some times the return type is got complex, like here in this method getblockchaininfo, the generator is just smart to convert these types from json to typescript interfaces.

"getBlockChainInfo": {
    "description": "The getblockchaininfo RPC provides information about the current state of the block chain.",
    "spec": "https://bitcoin.org/en/developer-reference#getblockchaininfo",
    "params": {},
    "result": {
      "type": {
        "chain": "string",
        "blocks": 0,
        "headers": 0,
        "bestblockhash": "string",
        "difficulty": 0,
        "mediantime": 0,
        "verificationprogress": 0,
        "chainwork": "string",
        "pruned": true,
        "softforks": [
          {
            "id": "string",
            "version": 0,
            "reject": {
              "status": true
            }
          }
        ],
        "bip9_softforks": {
          "csv": {
            "status": "string",
            "startTime": 0,
            "timeout": 0,
            "since": 0
          },
          "segwit": {
            "status": "string",
            "bit": 0,
            "startTime": 0,
            "timeout": 0,
            "since": 0
          }
        }
      },
      "required": true,
      "description": ""
    }
  }

you just have to copy the method's response example provided by it's reference, BUT with some modifications

Methods Spec:

  • All Method Names should be in lowerCamalCase, also for the parameters name.
  • If the method takes no params just make the params object empty "params": {}
  • if the one of the params is optional set "required" to false (:trollface: ).
  • If the result is an Object you should edit the values to this
    • type of number just make it 0 ( it could be any arbitrary number)
    • type of string make it "string" ( it could be any arbitrary string but let's make it a spec)
    • type of boolean make it true ( it could be any false too)
  • same goes to the params ⬆️ .
    see more examples in the json files, it will help you a lot.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions