Search…
Generate Address's
The create method of the receive endpoint generates a unique Bitcoin address to which the customer may send payments.
get
https://blockchainapi.org
/api/btc?method=create
Generate an address
The following block shows an example of the request URL:
Note: make sure you place your callback URL last or it will not set correctly

Example code

PHP
Python
Node JS
C#
<?php
$secret = "7j0ap91o99cxj8k9";
$my_address = "1LisLsZd3bx8U1NYzpNHqpo8Q6UCXKMJ4z";
$addressType = "bech32"; // bech32 | legacy | p2sh-segwit
$my_callback_url = "http://example.com/callback?invoice_id=1234&secret=" . $secret;
$api_base = "https://blockchainapi.org/api/btc";
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $api_base . "?method=create&address_type=".$addressType."&address=" . $my_address . "&callback=" . $my_callback_url
));
$response = curl_exec($curl);
$http_status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($http_status_code == 200) {
$decoded = json_decode($response, true);
echo "Please send the payment to the following Bitcoin address: " . $decoded["success"]["input_address"];
echo "The current estimated fee is: ".$decoded["success"]["estimated_transaction_fee"].' BTC';
} else {
echo "Sorry, an error occurred: " . $response["error"];
}
?>
# Importing the requests library
import requests
# Api-endpoint
URL = "https://blockchainapi.org/api/btc?method=create"
# Parameters
myAddress = "1LisLsZd3bx8U1NYzpNHqpo8Q6UCXKMJ4z"
mySecret = "7j0ap91o99cxj8k9"
myCallback = "http://example.com/callback?invoice_id=1234&secret=" + mySecret
# Defining a params dict for the parameters to be sent to the API
PARAMS = {'address':myAddress, 'callback':myCallback}
# Sending get request and saving the response as response object
r = requests.get(url = URL, params = PARAMS)
# Extracting data in json format
data = r.json()
# Extracting input_address & estimated_transaction_fee
input_address = data['success']['input_address']
estimatedFee = data['success']['estimated_transaction_fee']
# Printing the output
print("Please pay to the following address: %s\nThe estimated fee in BTC is: %s"
%(input_address, estimatedFee))
const request = require('request');
const http = require('http');
// Define our custom values
var my_address = "1LisLsZd3bx8U1NYzpNHqpo8Q6UCXKMJ4z";
var my_address_type = "bech32"; // bech32 | legacy | p2sh-segwit
var my_secret = "H78SY8DIJIDAID8JHD";
var my_callback = "http://example.com/callback?invoice_id=1234&secret=" + my_secret;
// BlockchainAPI endpoint
let endpoint = 'https://blockchainapi.org/api/btc?method=create&address=' + my_address + "&address_type=" + my_address_type + "&callback=" + my_callback;
// Request options
let options = {json: true};
// Define server variables
var port = 8181;
var hostname = "localhost";
var input_address = "";
var destination = "";
var fee_percentage = "";
var callback_url = "";
var estimated_transaction_fee = "";
var miners_fee = "";
var tor = "";
var setting = "";
request(endpoint, options, (error, res, body) => {
if (error) {
return console.log(error)
};
if (!error && res.statusCode == 200) {
// do something with JSON, using the 'body' variable
var response = JSON.parse(JSON.stringify(body));
if(response.success) {
// Good, we managed to create an address
console.log('Good, we managed to get a success response');
// Now dig into the values
input_address = response.success.input_address;
destination = response.success.destination;
fee_percentage = response.success.fee_percent;
callback_url = response.success.callback_url;
estimated_transaction_fee = response.success.estimated_transaction_fee;
miners_fee = response.success.miners_fee;
tor = response.success.tor;
setting = response.success.setting;
} else {
// Failed to get success response
console.log('Bad, failed to get success response');
}
};
});
// Initialise the server on port 8181
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-type', 'text/html');
// Show the "Please send the payment to..."
if(input_address !== null) {
res.write('<p>Please send the payment to the following Bitcoin address: ' + input_address + '</p>');
} else {
res.write('<p>Failed to create a new address to pay to</p>');
}
res.end('Page fully loaded');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
using System;
using System.Net;
using System.IO;
using Newtonsoft.Json;
public class Program
{
public static void Main()
{
string html = string.Empty;
string my_secret = "7j0ap91o99cxj8k9";
string my_callback = "http://example.com/callback?invoice_id=1234&secret=" + my_secret;
string my_address_type = "bech32"; // bech32 | legacy | p2sh-segwit
string my_address = "1LisLsZd3bx8U1NYzpNHqpo8Q6UCXKMJ4z";
string endpoint = @"https://blockchainapi.org/api/btc?method=create&address_type=" + my_address_type + "&address=" + my_address + "&callback=" + my_callback;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(endpoint);
request.AutomaticDecompression = DecompressionMethods.GZip;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
using (Stream stream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(stream))
{
html = reader.ReadToEnd();
// Check if we found a success response
dynamic result = JsonConvert.DeserializeObject(html);
string address = result.success.address;
Console.Write("Send the payment to the following address: " + address);
}
}
}
Copy link
On this page
get
Generate an address
Example code