Hello,
I hope I’m in the right channel with the following question. If not, please move me into the right channel.
I’m new in this space and I try to initiating a transaction to NIS (Testnet http://50.3.87.123:7890) via API.
Code (PHP):
$tx_ar['data']['transaction']['timeStamp'] = time();
$tx_ar['data']['transaction']['amount'] = '1000000000';
$tx_ar['data']['transaction']['fee'] = '3000000';
$tx_ar['data']['transaction']['recipient'] = 'TB5GYVPBUWFRZY337I3KCET5ID27B5WGDRNECPAX'; // Address
$tx_ar['data']['transaction']['type'] = '257';
$tx_ar['data']['transaction']['deadline'] = time() + 3600;
$tx_ar['data']['transaction']['message']['payload'] = 'test';
$tx_ar['data']['transaction']['message']['type'] = '1';
$tx_ar['data']['transaction']['version'] = '-1744830463'; // test network version
$tx_ar['data']['transaction']['signer'] = 'ef869ab819575be7efa7a2e4ce1fe9169eff4e474b87c223c2bd8a5e06c5d4b1'; // publicKey
$tx_ar['data']['privateKey'] = 'hidden...';
$tx_json = json_encode($tx_ar);
$dat = curl_init();
curl_setopt($dat, CURLOPT_URL, 'http://50.3.87.123:7890/transaction/announce');
curl_setopt($dat, CURLOPT_POST, TRUE);
curl_setopt($dat, CURLOPT_POSTFIELDS, $tx_json);
curl_setopt($dat, CURLOPT_CONNECTTIMEOUT , 10);
curl_setopt($dat, CURLOPT_TIMEOUT, 60);
curl_setopt($dat, CURLOPT_HEADER, 0);
curl_setopt($dat, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($tx_json)));
curl_setopt($dat, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($dat);
curl_close($dat);
$response_string = json_decode($response, TRUE);
The JSON Object (JSON_PRETTY_PRINT):
{
"data": {
"transaction": {
"timeStamp": 1517429694,
"amount": "1000000000",
"fee": "3000000",
"recipient": "TB5GYVPBUWFRZY337I3KCET5ID27B5WGDRNECPAX",
"type": "257",
"deadline": 1517433294,
"message": {
"payload": "test",
"type": "1"
},
"version": "-1744830463",
"signer": "ef869ab819575be7efa7a2e4ce1fe9169eff4e474b87c223c2bd8a5e06c5d4b1"
},
"privateKey": "hidden :)"
}
}
I receive the response
error: "Internal Server Error"
Message: "net.minidev.json.JSONObject cannot be cast to java.lang.String"
I have read this post, but I did not find the solution there:
net.minidev.json.JSONObject cannot be cast to java.lang.String
I think I’m on the brink of solving this, just need a little nudge.
It would be nice if someone could help me.
(Sorry for my bad english)