Blockchain Developer APIs (2024)

Accept bitcoin payments seamlessly

You provide an extended public key (xPub) and we generate a unique, unused corresponding address for your customers to send payment to. We notify you of payments to that address instantly using a callback URL of your choosing.

Introduction

The Blockchain Receive Payments API V2 is the quickest and easiest way to begin accepting automated bitcoin payments. Consisting of just a simple HTTP GET request, you can be up and running in minutes.

One of the difficulties involved with receiving bitcoin payments is the need to generate a unique address for each new user or invoice. These addresses need to monitored and stored securely. The blockchain receive payments API takes care of the generation and monitoring of addresses. We will notify your server using a simple callback whenever a payment is received.

    Generating a Receiving Address [GET]

    Provide unique, unused bitcoin addresses to your customers

    xPubs can be created with our new Blockchain Wallet

    https://api.blockchain.info/v2/receive?xpub=$xpub&callback=$callback_url&key=$key

    As defined in BIP 44, wallet software will not scan past 20 unused addresses. Given enough requests from this API that don't have a matching payment, you could generate addresses past this horizon, which would make spending funds paid to those addresses quite difficult. For this reason, this API will return an error and refuse to generate new addresses if it detects it would create a gap of over 20 unused addresses. If you encounter this error, you will either need to switch to a new xPub (within the same wallet is fine), or receive a payment to one of the previous 20 created addresses.

    https://api.blockchain.info/v2/receive?xpub=$xpub&callback=$callback_url&key=$key&gap_limit=$gap_limit

      Derive an unused address using your xPub:

      curl https://api.blockchain.info/v2/receive?xpub=xpub6CWiJoiwxPQni3DFbrQNHWq8kwrL2J1HuBN7zm4xKPCZRmEshc7Dojz4zMah7E4o2GEEbD6HgfG7sQid186Fw9x9akMNKw2mu1PjqacTJB2&callback=https%3A%2F%2Fmystore.com%3Finvoice_id%3D058921123&key=[yourkeyhere]

      Have your customer send bitcoin to the address contained in the response:

      Response: 200 OK, application/json

      { "address": "19jJyiC6DnKyKvPg38eBE8R6yCSXLLEjqw", "index": 23, "callback": "https://mystore.com?invoice_id=058921123"}

      PHP Example

        $secret = 'ZzsMLGKe162CfA5EcG6j'


        $my_xpub =

        '{YOUR XPUB ADDRESS}'

        ;

        $my_api_key =

        '{YOUR API KEY}'

        ;

        $my_callback_url = 'https://mystore.com?invoice_id=058921123&secret='.$secret;

        $root_url = 'https://api.blockchain.info/v2/receive';

        $parameters = 'xpub=' .$my_xpub. '&callback=' .urlencode($my_callback_url). '&key=' .$my_api_key;

        $response = file_get_contents($root_url . '?' . $parameters);

        $object = json_decode($response);


        Balance Updates [POST]

        Monitor addresses for received and spent payments

        This method monitors an address of your choice for received and / or spent payments. You will be sent an HTTP notification immediately when a transaction is made, and subsequently when it reaches the number of confirmations specified in the request.

        You are required to specify the request's notification behaviour. Setting the behaviour to 'DELETE' will delete the request after the first relelvant notification is sent to your callback address. Setting the behaviour to 'KEEP' will send additional notifications every time a transaction with the specified confirmations and operation type is sent to or from the address in the request.

        Operation type is an optional parameter indicating whether the address will be monitored for received or spent transactions, or both. By default both operation types are monitored.

        You may also optionally specify the number of confirmations a transaction reaches before being sent a notification. Note that you will receive a notification at 0 confirmations (i.e. immediately when the transaction is made), and again when it reaches the number of confirmations specified in the request (3 confirmations by default).

        https://api.blockchain.info/v2/receive/balance_update

        • address- The address you would like to monitor
        • callback- The callback URL to be notified when a payment is received.
        • callback- The callback URL to be notified when a payment is received. Remember to URL Encode the callback url when calling the create method.
        • key- Your blockchain.info receive payments v2 api key.
        • onNotification- The request notification behaviour ('KEEP' | 'DELETE).
        • confs- Optional (Default 3). The number of confirmations the transaction needs to have before a notification is sent.
        • op- Optional (Default 'ALL'). The operation type you would like to receive notifications for ('SPEND' | 'RECEIVE' | 'ALL').

        Monitor an address for every received payment with 5 confirmations:

        curl "curl -H "Content-Type: text/plain" --data '{"key":"[your-key-here]","addr":"183qrMGHzMstARRh2rVoRepAd919sGgMHb","callback":"https://mystore.com?invoice_id=123","onNotification":"KEEP", "op":"RECEIVE", "confs": 5}' https://api.blockchain.info/v2/receive/balance_update

        Response: 200 OK, application/json

        { "id": 70, "addr": "183qrMGHzMstARRh2rVoRepAd919sGgMHb", "op": "RECEIVE", "confs": 5, "callback": "https://mystore.com?invoice_id=123", "onNotification": "KEEP"}

        The id in the response can be used to delete the request:

        curl -X DELETE "https://api.blockchain.info/v2/receive/balance_update/70?key=[your-key-here]

        Response: 200 OK, application/json

        { "deleted": true}

        Block Notification [POST]

        This method allows you to request callbacks when a new block of a specified height and confirmation number is added to the blockchain.

        As with balance update requests, you are required to specify the request's notification behaviour to either 'KEEP' or 'DELETE'.

        Height is an optional parameter indicating at which height you would like to receive a block notification - if unspecified, this will be the height of the next block to arrive.

        Confs is another optional parameter indicating how many confirmations a block should have when a notification is sent.

        https://api.blockchain.info/v2/receive/block_notification

        • callback- The callback URL to be notified when a block that matches your query is added.
        • key- Your blockchain.info receive payments v2 api key.
        • onNotification- The request notification behaviour ('KEEP' | 'DELETE).
        • confs- Optional (Default 1). The number of confirmations the transaction needs to have before a notification is sent.
        • height- Optional (Default current chain height + 1). The height at which a notification should be sent.

        Request a single notification when the Bitcoin Blockchain reaches 500,000 blocks:

        curl -H "Content-Type: text/plain" --data '{"key":"[your-key-here]","height":500000,"callback":"https://mysite.com/block?request_id=1234","onNotification":"DELETE"}' https://api.blockchain.info/v2/receive/block_notification

        Response: 200 OK, application/json

        { "id": 64, "height": 500000, "callback": "https://mysite.com/block?request_id=1234", "confs": 1, "onNotification": "DELETE"}

        The id in the response can be used to delete the request:

        curl -X DELETE "https://api.blockchain.info/v2/receive/block_notifcation/64?key=[your-key-here]"

        Response: 200 OK, application/json

        { "deleted": true}

        Implementing the Callback

        Processing the callback sent from blockchain.info

          Receive and Balance Update callbacks

          Please note, the callback url is limited to 255 characters in length.

          When a payment is received by a generated address, or by an address monitored by a balance update request, blockchain.info will notify the callback URL you specify. For balance update callbacks and additional notification will be sent once the transaction reaches the specified number of confirmations.

          • transaction_hash- The payment transaction hash.
          • address- The destination bitcoin address (part of your xPub account).
          • confirmations- The number of confirmations of this transaction.
          • value- The value of the payment received (in satoshi, so divide by 100,000,000 to get the value in BTC).
          • {custom parameter}- Any parameters included in the callback URL will be passed back to the callback URL in the notification. You can use this functionality to include parameters in your callback URL like invoice_id or customer_id to track which payments are associated with which of your customers.

          Block Notification callbacks

          A block notification is sent every time a new block is added to the blockchain, and matches the height and number of confirmations set in the notification request.

          • hash- The block hash.
          • confirmations- The number of confirmations of this block.
          • height - The block height.
          • timestamp - The unix timestamp indicating when the block was added.
          • size- The block size in bytes.
          • {custom parameter}- Any parameters included in the callback URL will be passed back to the callback URL in the notification.

          PHP Example

            An example callback as a result of the above PHP example.

            $real_secret = 'ZzsMLGKe162CfA5EcG6j';

            $invoice_id = $_GET['invoice_id']; //invoice_id is passed back to the callback URL

            $transaction_hash = $_GET['transaction_hash'];

            $value_in_satoshi = $_GET['value'];

            $value_in_btc = $value_in_satoshi / 100000000;

            //Commented out to test, uncomment when live

            if ($_GET['test'] == true) {

            return

            }

            try {

            //create or open the database

            $database = new SQLiteDatabase('db.sqlite', 0666, $error);

            } catch(Exception $e) {

            die($error);

            }

            //Add the invoice to the database

            $stmt = $db->prepare("replace INTO invoice_payments (invoice_id, transaction_hash, value) values(?, ?, ?)");

            $stmt->bind_param("isd", $invoice_id, $transaction_hash, $value_in_btc);

            if($stmt->execute()) {

            echo "*ok*";

            }

            Expected Callback Response

              In order to acknowledge successful processing of the callback, your server should respond with the text "*ok*" (no quotes), in plain-text, no HTML. If the server responds with anything else, or nothing, the callback will be resent again for every new block (approximately every 10 minutes) up to 1000 times (1 week). Callback domains which appear dead or never return the "*ok*" response may be blocked from the service.

              Check xPub address gap [GET]

                Check the index gap between last address paid to and the last address generated using the using the checkgap endpoint. Use the xpub you want to check and your API key like so:

                curl "https://api.blockchain.info/v2/receive/checkgap?xpub=[yourxpubhere]]&key=[yourkeyhere]""
                { "gap": 2}

                Callback Logs [GET]

                Debug outstanding payments

                  See logs related to callback attempts using the callback_logs endpoints. Use the exact callback in question and your API key like so:

                  curl "https://api.blockchain.info/v2/receive/callback_log?callback=https%3A%2F%2Fmystore.com%3Finvoice_id%3D05892112%26secret%3DZzsMLGKe162CfA5EcG6j&key=[yourkeyhere]"
                  [ { "callback": "https://mystore.com?invoice_id=058921123&secret=ZzsMLGKe162CfA5EcG6j&key=[yourkeyhere]", "called_at": "2015-10-21T22:43:47Z", "raw_response": "*bad*", "response_code": 200 }, { "callback": "http://mystore.com?invoice_id=058921123&secret=ZzsMLGKe162CfA5EcG6j&key=[yourkeyhere]", "called_at": "2015-10-21T22:43:55Z", "raw_response": "*bad*", "response_code": 200 }]

                  Security

                    A custom secret parameter should be included in the callback URL. The secret will be passed back to the callback script when the callback is fired, and should be checked by your code for validity. This prevents someone from trying to call your servers and falsely mark an invoice as 'paid'.

                    Currency Conversion

                      Use the Exchange Rates API to convert values in local currencies to BTC. The Demo Apps below include examples of how to do this.

                      If you would like convert payments received in Bitcoin to fiat currency quickly use a bitcoin address from an exchange wallet.

                      Double Spends & Chargebacks

                        A double spend occurs when a malicious user spends the same BTC twice. A payment that initial appears successful could be reversed at a later date. This is counteracted by waiting for the transaction to be included in the blockchain and reaching a number of confirmations. 6 confirmations is generally considered safe for high value transactions.

                        Validate the transaction confirmations in the callback script by checking $_GET['confirmations'] parameter. It is recommended you acknowledge the transaction at zero confirmations but only trust the transaction after one confirmation. For example, if purchasing a product, we would show the order as successful at zero confirmations (the first callback, but do not echo "*ok*" yet), but only ship the product when 4 or more confirmations are reached. See the PHP demo callback.php for an example.

                        if ($_GET['confirmations'] {'>'}= 6)

                        {

                        //Insert into confirmed payments

                        echo '*ok*';

                        }

                        else

                        {

                        //Insert into pending payments

                        //Don't print *ok* so the notification resent again on next confirmation

                        }

                        Address Expiration

                          Receive addresses never expire and will continue to be monitored until an "*ok*" is received in the callback response or blockchain.info has notified the callback 1000 times.

                          Fair Usage

                            There is no limit to the number of receiving address which can be generated (as long as the 20 address gap limitation is met), the service is designed to monitor millions of addresses.

                            Callback domains which appear dead or never return the "*ok*" response may be blocked from the service.

                            Blockchain Developer APIs (2024)

                            FAQs

                            What are APIs in blockchain? ›

                            A blockchain API is an application programming interface that allows developers to interact with a blockchain. By using a blockchain API, developers can access the data and functionality of a blockchain without having to build their own blockchain platform.

                            How do I get blockchain API? ›

                            To Get Started
                            1. Create or log into your existing Blockchain.com Exchange account.
                            2. Select API from the drop down menu.
                            3. Fill out form and click “Create New API Key Now”
                            4. Once generated you can view your keys under API Settings.

                            Does blockchain use REST API? ›

                            REST APIs can be used in blockchain development to allow applications and services to interact with a blockchain and access its data and functionality. For example, a blockchain-based application might use a REST API to: Query the blockchain for information about specific transactions, blocks, or addresses.

                            What is blockchain vs API? ›

                            API vs Blockchain

                            A blockchain is about storing and securing sensitive data onto a ledger that gets validated through consensus among network nodes. On the other hand, API is the collection of protocols and data that acts as a base for other developers to modify and create an app.

                            What are 3 most common APIs? ›

                            Today, there are three categories of API protocols or architectures: REST, RPC and SOAP.

                            What are four examples of APIs? ›

                            7 Examples of APIs in Use Today
                            • Twitter Bots.
                            • Log-In Using XYZ.
                            • Weather Snippers.
                            • Pay with PayPal.
                            • Google Maps.
                            • Travel Booking.
                            • E-Commerce.

                            Is blockchain API free? ›

                            Blockchain.com APIs

                            An easy and secure way to accept bitcoin payments on any website, for free.

                            Does CoinBase have an API? ›

                            You'll need to create a Coinbase account and generate an API key before you can access our API endpoints.

                            Does blockchain use JSON? ›

                            In Blockchain technology, JSON-RPC facilitates communication between Blockchain nodes and client applications, such as wallets or dApps. JSON-RPC enables the client application to send requests to the node to perform certain actions, such as sending a transaction or retrieving information about the Blockchain.

                            Is Javascript used in blockchain? ›

                            Blockchain developers use javascript in web3. js and ethereum. js which it helps you connect your frontend of application to connect with ethereum network and smart contracts. Another popular use of javascript in blockchain is Hyperledger Fabric SDK for node.

                            What programming language does blockchain run on? ›

                            Blockchain Programming developers support the use of C++ as it is decently abundant in terms of run-time polymorphism, function overloading, and multi-threading. It allows developers to mold the data according to their needs.

                            What are the 4 types of blockchain? ›

                            There are four main types of blockchain networks: public blockchains, private blockchains, consortium blockchains and hybrid blockchains. Each one of these platforms has its benefits, drawbacks and ideal uses.

                            Should I use Python or Javascript for blockchain? ›

                            Python lets developers create a simple blockchain in less than 50 lines of code. Especially for a blockchain that is addressing an Internet of Things case, Python is recommended. It eases the job of building blocks and linking them together.

                            What is the best API for crypto? ›

                            Best Cryptocurrency APIs
                            • CoinGecko.
                            • Mineable Coins.
                            • Crypto Asset Market Data.
                            • Blockchain.
                            • CoinAPI - REST.
                            • Coinbase.
                            • Crypto Arbitrage.
                            • Chain.

                            What is a real life example of an API? ›

                            Weather data is a popular API example that we come across regularly. Rich weather snippets appear ubiquitous, appearing on all platforms such as Google Search, Apple's Weather app, and even your smart home device.

                            What are APIs in coding? ›

                            API stands for application programming interface, which is a set of definitions and protocols for building and integrating application software. Download the API owner's manual.

                            Is SQL an API? ›

                            SQL is not an API. It's a language. That's what the "L" stands for. The most important property of an API is that it acts as a layer of abstraction between the user, and the data.

                            Can I build an API for free? ›

                            1. Amazon AWS Free Tier and Amazon API Gateway. AWS Free Tier offers free access to Amazon API Gateway and many other such services to you. With the free access comes limitations and the constraints limit you to 1 million API calls per month or 750,000 connection minutes.

                            Can I run my own blockchain? ›

                            If you want to create a cryptocurrency that is truly new or innovative in some way, then building your own blockchain to support that coin is probably your best option. You can design your native coin in any way that you like.

                            Do you have to pay to use an API? ›

                            Some APIs make their keys freely available, while others require clients to pay for one. Either way, you'll most likely need to sign up with the service. You'll then have a unique identifier assigned to you, which you will include in your calls.

                            What API does crypto use? ›

                            The Crypto.com Exchange API v1 provides developers with a REST, and websocket API.

                            How do I make a Coinbase API? ›

                            Select API from the menu. Under Profile Information, select the API Settings tab, then select + New API Key. Select your profile and appropriate permissions, create a passphrase, and then enter in your 2-step verification code. Finally, select Create API Key at the bottom to make a unique key.

                            Is Coinbase Pro API free? ›

                            Creating an account on Coinbase Pro and using the API is free, but when it comes to trading fees start to apply.

                            What programming language is Coinbase? ›

                            The Coinbase family of components even includes more complex elements like UI widgets and themes, making visual consistency easier and faster than ever. And, yes, they were all written in TypeScript.

                            Does Coinbase have a Python API? ›

                            Project description. The official Python library for the Coinbase API.

                            Do Blockchains use SQL? ›

                            To incorporate the increasingly important blockchain technology into Information Systems curriculum, one approach is to store blockchain data in a SQL database, thus allowing fast data access and a simpler understanding of the underlying concepts.

                            Do you use Python for blockchain? ›

                            Python is an excellent language for Blockchain projects because it's secure, performant, scalable and very safe. Although Blockchain is written in C++, many developers and data scientists turn to other languages to build their blockchains. Here are five good reasons why Python is an excellent language for a Blockchain.

                            Does blockchain use HTTP? ›

                            Decentralized applications running on any of the Layer 1 blockchains, like Ethereum or Solana, interface with HTTP-based services using what's known as an oracle.

                            Do I need node js for blockchain? ›

                            Node. js is a relatively new option for blockchain development, which is why it's essential to hire experienced Node. js developers who will be able to build a reliable product.

                            How difficult is blockchain coding? ›

                            There is no doubt that blockchain coding is not easy. It requires a lot of technical expertise and knowledge to be able to code a blockchain. However, many resources are available to help people learn how to code a blockchain.

                            Should I learn JavaScript for blockchain development? ›

                            Furthermore, JavaScript is the best language for blockchain development when it comes to off-chain programming. Using JavaScript, in combination with Moralis, makes it relatively easy to set up the necessary functionalities that your dApps need.

                            Can a non technical person learn blockchain? ›

                            Yes definitely, non-IT people can learn blockchain without IT background. Enrol in a good course and get yourself certified. Invest enough time into learning and practicing the skills.

                            What is blockchain developer salary? ›

                            How much does a Blockchain Developer make? As of Mar 4, 2023, the average annual pay for a Blockchain Developer in the United States is $129,179 a year. Just in case you need a simple salary calculator, that works out to be approximately $62.11 an hour. This is the equivalent of $2,484/week or $10,764/month.

                            What are the top 3 Blockchains? ›

                            According to Menon, the top three blockchain frameworks for these use cases are R3 Corda, Hyperledger and Ethereum, with EOSIO and ConsenSys Quorum gaining ground.

                            What are the three pillars of blockchain? ›

                            There are three key components to blockchain technology: The distributed ledger, the consensus mechanism, and the smart contracts.

                            What are the six layers of blockchain? ›

                            1. Blockchain architecture
                            • The hardware layer. The first layer of the blockchain consists of hardware, like network connections, the computers within the network and data servers. ...
                            • The data layer. ...
                            • The network layer. ...
                            • The consensus layer. ...
                            • The application layer. ...
                            • Layer 0. ...
                            • Layer 1. ...
                            • Layer 2.
                            Sep 19, 2022

                            Is Python enough to learn Solidity? ›

                            Consequently, I would recommend learning Javascript or Python prior to learning Solidity for those new to programming. While this may take longer, it'll help you in the long run by building a stronger foundation as a developer.

                            What language is web3 written in? ›

                            C++ As a high-level programming language, C++ also presses its claim as a reliable choice for web3 programming. Interestingly, C++ is not only one of the top blockchain programming languages but also a staple favorite of programmers in various domains.

                            What coding language is used for web3? ›

                            Solidity is the most widely used smart contract programming language in web3, having been created by an Ethereum team. The language is object-oriented, high-level, and Turing-complete. These characteristics are a result of the language's heavy dependence on C++, Python, and JavaScript.

                            What is the best coding for crypto? ›

                            C++, introduced back in 1985 by Bjarne Stroustrup, is the best programming language for cryptocurrency development. The language follows OOPs methodology and is highly used for developing cryptocurrencies like Bitcoin, Litecoin, Ripple, Stellar, and EOS.

                            Does bitcoin use an API? ›

                            These Cryptocurrency APIs allow you to interact with Bitcoin in particular, as well as a multitude of other blockchain-based projects such as Ethereum or Dogecoin. They encompass a variety of functions, from viewing wallet contents, tracking market prices, or even sending and receiving transactions.

                            Is there an API for bitcoin? ›

                            Coinbase API is a flexible and secure tool. It supports Bitcoin, Bitcoin Cash, Litecoin, and Ethereum. Coinbase provides excellent wallet services with constant notifications about every transaction. The API technology is based on Node.

                            What is an API and examples? ›

                            APIs are mechanisms that enable two software components to communicate with each other using a set of definitions and protocols. For example, the weather bureau's software system contains daily weather data. The weather app on your phone “talks” to this system via APIs and shows you daily weather updates on your phone.

                            What is API used for in crypto? ›

                            What Can an API Do? A cryptocurrency exchange's API acts as a middleman between you and your broker so you can perform various transactions. These may include buying and selling assets, viewing real-time market data, and executing more sophisticated trading strategies.

                            What is the purpose of APIs? ›

                            Many people ask themselves, “What is an API?” API is the acronym for application programming interface — a software intermediary that allows two applications to talk to each other. APIs are an accessible way to extract and share data within and across organizations.

                            What is API in ethereum? ›

                            Ethereum Blockchain APIs ( Eth1 + Eth2 )

                            Our Ethereum GraphQL APIs provide a simple interface to query Ethereum which includes ETH1 (Proof of Work) and ETH2 (Proof of Stake) network. Using our APIs, developers can query any ERC tokens, NFTs, smart contracts, Dapp related data.

                            Top Articles
                            Latest Posts
                            Article information

                            Author: Domingo Moore

                            Last Updated:

                            Views: 5876

                            Rating: 4.2 / 5 (53 voted)

                            Reviews: 92% of readers found this page helpful

                            Author information

                            Name: Domingo Moore

                            Birthday: 1997-05-20

                            Address: 6485 Kohler Route, Antonioton, VT 77375-0299

                            Phone: +3213869077934

                            Job: Sales Analyst

                            Hobby: Kayaking, Roller skating, Cabaret, Rugby, Homebrewing, Creative writing, amateur radio

                            Introduction: My name is Domingo Moore, I am a attractive, gorgeous, funny, jolly, spotless, nice, fantastic person who loves writing and wants to share my knowledge and understanding with you.