Quick Start
Good to know: A quick start guide can be good to help folks get up and running with your API in a few steps. Some people prefer diving in with the basics rather than meticulously reading every page of documentation!

Create address

Node
PHP
1
const crypto = require('crypto');
2
const axios = require('axios');
3
4
// testnet
5
var hostname = "https://testnetrest.metacoin.network:20923";
6
// mainnet
7
// hostname = "https://rest.metacoin.network:20923";
8
9
var public_key = "-----BEGIN PUBLIC KEY-----\nMIGbMBAGByqGSM49AgEGBSuBBAAjA4GGAAQBBp5oHHFaATF1UIephJYgtW+u2+aT\nhZLxNgn5JZhgFXzvTUHlThZxb61eTXMMjyU/IloNznwtzRWuPq1oMDOMq9oBbT/t\nE4lgyPF5/QtzuhaaYRpr/ahZ4JSLyHOegkopXeic3UFUmkpb4mXuSGgu5mChuuUC\nktjfluGNtvXHOWYtqTU=\n-----END PUBLIC KEY-----";
10
// public_key = "MIGbMBAGByqGSM49AgEGBSuBBAAjA4GGAAQBBp5oHHFaATF1UIephJYgtW+u2+aThZLxNgn5JZhgFXzvTUHlThZxb61eTXMMjyU/IloNznwtzRWuPq1oMDOMq9oBbT/tE4lgyPF5/QtzuhaaYRpr/ahZ4JSLyHOegkopXeic3UFUmkpb4mXuSGgu5mChuuUCktjfluGNtvXHOWYtqTU=";
11
12
axios.post(hostname + '/address/bykey', {
13
'publickey': public_key
14
}, {
15
proxy: {
16
host: '127.0.0.1',
17
port: 8888
18
}
19
})
20
.then(function (response) {
21
if (response.status != 200) {
22
return Promise.reject("Metacoin server response error");
23
} else {
24
return Promise.resolve(response.data);
25
}
26
})
27
.then(function (mtc_address) {
28
// ["MT4FzIQCgRh0T1YD841OxjNd3dkfTJcEd41d17d3"]
29
console.log(mtc_address);
30
})
31
.catch(function (error) {
32
if (error.response.status == 404) {
33
console.log("Address not found");
34
} else {
35
console.log(error);
36
}
37
});
1
<?
2
// testnet
3
define('MTC_HOST', 'https://testnetrest.metacoin.network:20923');
4
// mainnet
5
// define('MTC_HOST', 'https://rest.metacoin.network:20923');
6
function mtc_post($uri, $param){
7
$curl = curl_init();
8
$opt = curl_setopt_array($curl, array(
9
CURLOPT_URL => MTC_HOST . $uri,
10
CURLOPT_RETURNTRANSFER => true,
11
CURLOPT_CONNECTTIMEOUT => 5,
12
CURLOPT_TIMEOUT => 20,
13
CURLOPT_SSL_VERIFYPEER => false,
14
CURLOPT_SSL_VERIFYHOST => false,
15
CURLOPT_POSTFIELDS => http_build_query($param),
16
CURLOPT_POST => true,
17
CURLOPT_HTTPHEADER => array('Content-Type: application/x-www-form-urlencoded')
18
));
19
$body = curl_exec($curl);
20
21
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
22
$err_msg = '';
23
$err_code = curl_errno($curl);
24
if ($err_code) {
25
$err_msg = curl_error($curl);
26
}
27
28
printf("Response Http Code: %s, msg: %s\n", $http_code, $body);
29
if ($err_code) {
30
printf("Response CurlCode: %s, msg: %s\n", $err_code, $body);
31
}
32
33
curl_close($curl);
34
$curl = null;
35
36
return $body;
37
}
38
39
$param = array(
40
'publickey' => "-----BEGIN PUBLIC KEY-----\nMIGbMBAGByqGSM49AgEGBSuBBAAjA4GGAAQBBp5oHHFaATF1UIephJYgtW+u2+aT\nhZLxNgn5JZhgFXzvTUHlThZxb61eTXMMjyU/IloNznwtzRWuPq1oMDOMq9oBbT/t\nE4lgyPF5/QtzuhaaYRpr/ahZ4JSLyHOegkopXeic3UFUmkpb4mXuSGgu5mChuuUC\nktjfluGNtvXHOWYtqTU=\n-----END PUBLIC KEY-----");
41
42
$body = mtc_post('/address/bykey', $param);
43
printf("Address list : %s\n", $body);
Good to know: Using tabs to separate out different languages is a great way to present technical examples or code documentation without cramming your docs with extra sections or pages per language.

Make your first request

To make your first request, send an token transfer
post
http://testnetrest.metacoin.network:20922
/transfer
Transfer Metacoin or Token
PHP
Node
Python
1
define('MTC_HOST', 'https://testnetrest.metacoin.network:20923');
2
// mainnet
3
// define('MTC_HOST', 'https://rest.metacoin.network:20923');
4
5
6
function mtc_get($uri){
7
$curl = curl_init();
8
$opt = curl_setopt_array($curl, array(
9
CURLOPT_URL => MTC_HOST . $uri,
10
CURLOPT_RETURNTRANSFER => true,
11
CURLOPT_CONNECTTIMEOUT => 5,
12
CURLOPT_TIMEOUT => 20,
13
CURLOPT_SSL_VERIFYPEER => false,
14
CURLOPT_SSL_VERIFYHOST => false,
15
CURLOPT_POST => false,
16
CURLOPT_CUSTOMREQUEST => 'GET',
17
));
18
19
$body = curl_exec($curl);
20
21
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
22
$err_msg = '';
23
$err_code = curl_errno($curl);
24
if ($err_code) {
25
$err_msg = curl_error($curl);
26
}
27
28
printf("Response Http Code: %s, msg: %s\n", $http_code, $body);
29
if ($err_code) {
30
printf("Response CurlCode: %s, msg: %s\n", $err_code, $body);
31
}
32
33
curl_close($curl);
34
$curl = null;
35
36
return $body;
37
}
38
39
function mtc_post($uri, $param){
40
$curl = curl_init();
41
$opt = curl_setopt_array($curl, array(
42
CURLOPT_URL => MTC_HOST . $uri,
43
CURLOPT_RETURNTRANSFER => true,
44
CURLOPT_CONNECTTIMEOUT => 5,
45
CURLOPT_TIMEOUT => 20,
46
CURLOPT_SSL_VERIFYPEER => false,
47
CURLOPT_SSL_VERIFYHOST => false,
48
CURLOPT_POSTFIELDS => http_build_query($param),
49
CURLOPT_POST => true,
50
CURLOPT_HTTPHEADER => array('Content-Type: application/x-www-form-urlencoded')
51
));
52
$body = curl_exec($curl);
53
54
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
55
$err_msg = '';
56
$err_code = curl_errno($curl);
57
if ($err_code) {
58
$err_msg = curl_error($curl);
59
}
60
61
printf("Response Http Code: %s, msg: %s\n", $http_code, $body);
62
if ($err_code) {
63
printf("Response CurlCode: %s, msg: %s\n", $err_code, $body);
64
}
65
66
curl_close($curl);
67
$curl = null;
68
69
return $body;
70
}
71
72
// sender address
73
$from_addr = "MTW95PhgJaQCc7L4K9I9GrU94d2zSd8DLjkrQ2b5";
74
75
// example private key. this key is not working
76
$from_private_key = "-----BEGIN EC PRIVATE KEY-----\r\nMIGkAg3vKK7Ap90qLaVMtxT2XbL1dEBBDCqmxUIZRO/CgFhUmBO3bXRUAn4pF2RX\r\nF9K+NCIw1OugBwYFK4uFzziOGlVLSqaO0xtEab0XEEACKhZANiAAQ5rGDv8H0m8m\r\nVpD64cMzobDGYJ4WeuBhlkpGexfl5PXh7G64TECZEXIrV4FSMUhuntu0CjB2wTJs\r\nNfRLakp5UMv1N2dIgF1CvoTBaWXNudk=\r\n-----END EC PRIVATE KEY-----\r\n";
77
$to_addr = "MT....";
78
$amount = "100000000"; // 1 MTC
79
$token = "0"; // token 0 is MTC
80
$tkey = mtc_get('/getkey/transfer/' . $from_addr);
81
82
$data = implode('|', array($from_addr, $to_addr, $token, $amount, $tkey));
83
openssl_sign($data, $signature, $from_private_key, OPENSSL_ALGO_SHA384);
84
85
$r = mtc_post('/transfer/',
86
array(
87
'from' => $from_addr,
88
'to' => $to_addr,
89
'token' => $token,
90
'amount' => $amount,
91
'signature' => base64_encode($signature),
92
'unlockdate' => '0',
93
'tags' => 'it is tag',
94
'memo' => 'it is memo',
95
'checkkey' => $tkey)
96
);
97
echo "Transfer $from_addr => $to_addr, Token $token, Amount $amount, TXID $r \r\n";
// require the myapi module and set it up with your API key
const myapi = require('myapi')(YOUR_API_KEY);
const newPet = away myapi.pet.create({
name: 'Wilson',
owner_id: 'sha7891bikojbkreuy',
species: 'Dog',
breed: 'Golden Retriever',
})
// Set your API key before making the request
myapi.api_key = YOUR_API_KEY
myapi.Pet.create(
name='Wilson',
owner_id='sha7891bikojbkreuy',
species='Dog',
breed='Golden Retriever',
)
Copy link
Edit on GitHub
On this page
Create address
Make your first request
post
/transfer