Skip to content

Instantly share code, notes, and snippets.

@sandoche
Last active August 1, 2018 08:54
Show Gist options
  • Save sandoche/5a49f928e4b363250fd483ce4073361f to your computer and use it in GitHub Desktop.
Save sandoche/5a49f928e4b363250fd483ce4073361f to your computer and use it in GitHub Desktop.
Interact with Motive API in PHP to create an account (this should also work with ARDOR, NXT, IGNIS)
<?php
/*
* References & examples
* https://docs.motive.network/api_examples.html#Get_Account_Id
* https://docs.motive.network/api.html#Get_Account_Id
* https://docs.motive.network/api_examples.html#Get_Account_Public_Key
* https://docs.motive.network/api.html#Get_Account_Public_Key
*
* Notes
* The user needs to do a transaction to confirm its address
* This method will return null if the address is already taken (and confirmed) by a user
*/
function generateKeyPair() {
$privateKey = "A private key that I generate randomly, that can also be a seed composed with a lot of words";
$url = "https://node.motive.network/nxt?requestType=getAccountId";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS,"secretPhrase=" . $privateKey);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($curl);
curl_close($curl);
// This call ensures that
$jsonRes = json_decode($res);
$account = $jsonRes->accountRS;
$url = "https://node.motive.network/nxt?requestType=getAccountPublicKey";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS,"account=" . $account);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($curl);
curl_close($curl);
if($res != "{}") {
$result["account"] = $account;
$result["private"] = $privateKey;
} else {
$result = null;
}
return $result;
}
?>
<?php
/*
* References & examples
* https://docs.motive.network/api.html#Send_Money
* https://docs.motive.network/api_examples.html#Send_Money
*/
function sendCoins() {
$privateKey = "private key of the account that makes the transaction";
$url = "https://node.motive.network/nxt?requestType=sendMoney";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS,"secretPhrase=" . $privateKey . "&recipient= " . $wallet . "&amountNQT=100000000&feeNQT=100000000&deadline=360");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($curl);
curl_close($curl);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment