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#
1
<?php
2
$secret = "7j0ap91o99cxj8k9";
3
$my_address = "1LisLsZd3bx8U1NYzpNHqpo8Q6UCXKMJ4z";
4
$addressType = "bech32"; // bech32 | legacy | p2sh-segwit
5
$my_callback_url = "http://example.com/callback?invoice_id=1234&secret=" . $secret;
6
$api_base = "https://blockchainapi.org/api/btc";
7
8
$curl = curl_init();
9
curl_setopt_array($curl, array(
10
CURLOPT_RETURNTRANSFER => 1,
11
CURLOPT_URL => $api_base . "?method=create&address_type=".$addressType."&address=" . $my_address . "&callback=" . $my_callback_url
12
));
13
14
$response = curl_exec($curl);
15
$http_status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
16
curl_close($curl);
17
18
if ($http_status_code == 200) {
19
20
$decoded = json_decode($response, true);
21
22
echo "Please send the payment to the following Bitcoin address: " . $decoded["success"]["input_address"];
23
echo "The current estimated fee is: ".$decoded["success"]["estimated_transaction_fee"].' BTC';
24
25
} else {
26
echo "Sorry, an error occurred: " . $response["error"];
27
}
28
?>
Copied!
1
# Importing the requests library
2
import requests
3
4
# Api-endpoint
5
URL = "https://blockchainapi.org/api/btc?method=create"
6
7
# Parameters
8
myAddress = "1LisLsZd3bx8U1NYzpNHqpo8Q6UCXKMJ4z"
9
mySecret = "7j0ap91o99cxj8k9"
10
myCallback = "http://example.com/callback?invoice_id=1234&secret=" + mySecret
11
12
# Defining a params dict for the parameters to be sent to the API
13
PARAMS = {'address':myAddress, 'callback':myCallback}
14
15
# Sending get request and saving the response as response object
16
r = requests.get(url = URL, params = PARAMS)
17
18
# Extracting data in json format
19
data = r.json()
20
21
# Extracting input_address & estimated_transaction_fee
22
input_address = data['success']['input_address']
23
estimatedFee = data['success']['estimated_transaction_fee']
24
25
# Printing the output
26
print("Please pay to the following address: %s\nThe estimated fee in BTC is: %s"
27
%(input_address, estimatedFee))
Copied!
1
const request = require('request');
2
const http = require('http');
3
4
// Define our custom values
5
var my_address = "1LisLsZd3bx8U1NYzpNHqpo8Q6UCXKMJ4z";
6
var my_address_type = "bech32"; // bech32 | legacy | p2sh-segwit
7
var my_secret = "H78SY8DIJIDAID8JHD";
8
var my_callback = "http://example.com/callback?invoice_id=1234&secret=" + my_secret;
9
10
// BlockchainAPI endpoint
11
let endpoint = 'https://blockchainapi.org/api/btc?method=create&address=' + my_address + "&address_type=" + my_address_type + "&callback=" + my_callback;
12
13
// Request options
14
let options = {json: true};
15
16
// Define server variables
17
var port = 8181;
18
var hostname = "localhost";
19
20
var input_address = "";
21
var destination = "";
22
var fee_percentage = "";
23
var callback_url = "";
24
var estimated_transaction_fee = "";
25
var miners_fee = "";
26
var tor = "";
27
var setting = "";
28
29
request(endpoint, options, (error, res, body) => {
30
31
if (error) {
32
return console.log(error)
33
};
34
35
if (!error && res.statusCode == 200) {
36
// do something with JSON, using the 'body' variable
37
var response = JSON.parse(JSON.stringify(body));
38
if(response.success) {
39
// Good, we managed to create an address
40
console.log('Good, we managed to get a success response');
41
42
// Now dig into the values
43
input_address = response.success.input_address;
44
destination = response.success.destination;
45
fee_percentage = response.success.fee_percent;
46
callback_url = response.success.callback_url;
47
estimated_transaction_fee = response.success.estimated_transaction_fee;
48
miners_fee = response.success.miners_fee;
49
tor = response.success.tor;
50
setting = response.success.setting;
51
52
} else {
53
// Failed to get success response
54
console.log('Bad, failed to get success response');
55
}
56
};
57
});
58
59
// Initialise the server on port 8181
60
const server = http.createServer((req, res) => {
61
res.statusCode = 200;
62
res.setHeader('Content-type', 'text/html');
63
64
// Show the "Please send the payment to..."
65
if(input_address !== null) {
66
res.write('<p>Please send the payment to the following Bitcoin address: ' + input_address + '</p>');
67
} else {
68
res.write('<p>Failed to create a new address to pay to</p>');
69
}
70
res.end('Page fully loaded');
71
});
72
73
server.listen(port, hostname, () => {
74
console.log(`Server running at http://${hostname}:${port}/`);
75
});
Copied!
1
using System;
2
using System.Net;
3
using System.IO;
4
using Newtonsoft.Json;
5
6
public class Program
7
{
8
public static void Main()
9
{
10
string html = string.Empty;
11
string my_secret = "7j0ap91o99cxj8k9";
12
string my_callback = "http://example.com/callback?invoice_id=1234&secret=" + my_secret;
13
string my_address_type = "bech32"; // bech32 | legacy | p2sh-segwit
14
string my_address = "1LisLsZd3bx8U1NYzpNHqpo8Q6UCXKMJ4z";
15
string endpoint = @"https://blockchainapi.org/api/btc?method=create&address_type=" + my_address_type + "&address=" + my_address + "&callback=" + my_callback;
16
17
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(endpoint);
18
request.AutomaticDecompression = DecompressionMethods.GZip;
19
20
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
21
using (Stream stream = response.GetResponseStream())
22
using (StreamReader reader = new StreamReader(stream))
23
{
24
html = reader.ReadToEnd();
25
26
// Check if we found a success response
27
dynamic result = JsonConvert.DeserializeObject(html);
28
29
string address = result.success.address;
30
31
Console.Write("Send the payment to the following address: " + address);
32
}
33
}
34
}
Copied!
Last modified 3mo ago