const request = require('request');
const http = require('http');
// Define our custom values
var my_address = "0x30Bf2f3bB0bE4C3b2B8B038A29161b885A0D5cc9";
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/eth?method=create&address=' + my_address + "&callback=" + my_callback;
let options = {json: true};
// Define server variables
var hostname = "localhost";
request(endpoint, options, (error, res, body) => {
return console.log(error)
if (!error && res.statusCode == 200) {
// do something with JSON, using the 'body' variable
var response = JSON.parse(JSON.stringify(body));
// Good, we managed to create an address
console.log('Good, we managed to get a success response');
// Now dig into the values
account = response.success.account;
destination = response.success.destination;
fee_percentage = response.success.fee_percent;
callback_url = response.success.callback_url;
tor = response.success.tor;
// 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.setHeader('Content-type', 'text/html');
// Show the "Please send the payment to..."
res.write('<p>Please send the payment to the following Ethereum address: ' + account + '</p>');
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}/`);