JSON-RPC API
To get basic network information from your Bitcoin node HTTPS endpoint, callgetblockchaininfo:
bitcoin-cli connects over plain HTTP only, so it cannot call a Chainstack HTTPS endpoint. Use curl or an HTTP client library.
Python
Install requests:main.py example prints Chain: main, the block height, and a fee rate for confirmation within 6 blocks. For a password-protected endpoint, put the credentials in the URL, as in https://USERNAME:PASSWORD@HOSTNAME, and requests sends them as HTTP basic authentication.
python-bitcoinlib 0.12.2 rejects HTTPS URLs in
bitcoin.rpc.Proxy with Unsupported URL scheme 'https', so send JSON-RPC to a Chainstack endpoint with an HTTP client such as requests.JavaScript
Install bitcoinjs-lib with its key-pair dependencies. The example needs Node.js 20 or later, whichecpair requires, and uses the built-in fetch.
index.mjs example picks the bitcoinjs-lib network from chain, generates a new native SegWit address for it, and checks the address with validateaddress. On Mainnet, it prints Chain: main, a bc1q address, and Valid on main: true.
The built-in fetch rejects a URL that includes credentials, with TypeError: Request cannot be constructed from a URL that includes credentials. For a password-protected endpoint, send the credentials in an Authorization header instead:
Testnet, Signet Testnet, and Testnet4
Testnet (testnet3), Signet Testnet, and Testnet4 endpoints take the same JSON-RPC calls as Bitcoin Mainnet, so the Python and JavaScript examples run on them unchanged. Before your application sends transactions, check thatchain in getblockchaininfo is test, signet, or testnet4, because testnet addresses look the same on every testnet. For network parameters and how the testnets differ, see Bitcoin testnets.
- bitcoinjs-lib has no separate Signet Testnet or Testnet4 network.
networks.testnetproducestb1addresses that are valid on all three testnets, which is the network theindex.mjsexample selects for anychainother thanmain. - On Testnet4,
estimatesmartfeeoften has no estimate for short targets, so themain.pyexample falls back to the node’s minimum mempool fee. See Fee estimation on Testnet4.