Transaction announce gave unexpected end of stream reached error message

Hi guys,

I’m trying to make a transaction using api: http://host:port/transaction/announce.

To get a quick overview of how am I doing this, here is some code:

String privateKeySender = "sender-private-key"; String publicKeySender = "sender-public-key"; ​String recipientAddress = "recipient-address"; Transaction transaction = new Transaction(System.currentTimeMillis(), publicKeySender, recipientAddress); byte[] data = transaction.getFinalByteArray(); String dataHex = bytesToHex(data); byte[] signature = transaction.sign(data, privateKeySender, publicKeySender).getBytes(); String signatureHex = bytesToHex(signature); System.out.println("data " + dataHex); System.out.println("signature " + signatureHex);

The Transaction.java is given at: https://gist.github.com/phabion/c2732255b0931c3f78a9

I followed the guidance given from here http://neweconomymovement.github.io/#creating-a-signed-transaction.

The transaction.sign() function above is taken from nem-core open source https://github.com/NewEconomyMovement/nem.core.

After I’ve got the data and the signature from above, I prepared a json object as follow:

{ "data": "010100000100006856a21a2b20000000623461313637313637616437376432633234393339666539396138383637373836666535653836336237346332343938663139393061656463356261616133360005ea060000000066b01a2b280000004d414e4f4445475a44365854534d323442524d4f5056574b36494d535648424f4147564e4158424500e876480000000000000000", "signature": "c200b1e0f5833b4255601c6b8cdc0224a36b3b45285402660b69e51621298fd6388a934224bfe1e919144fb90a2b1e79c27caa3f1fd8982755ce198f2248eb08" }

and I used postman to send the request and here is the response I’ve got back:

{ "timeStamp": 29129527, "error": "Internal Server Error", "message": "unexpected end of stream reached", "status": 500 }
There is nothing like this as given from Appendix B: NIS Errors http://neweconomymovement.github.io/

I also noticed that the System.currentTimeMilis is not what timestamp is aimed to be. According to Nem document:

The number of seconds elapsed since the creation of the nemesis block. Future timestamps are not allowed. Transaction validation detects future timestamps and returns an error in that case. Network time synchronization ensures that any NEM software component will use valid timestamps when creating transactions.
First I couldn’t find any document how to exactly create the timestamp. So I put the current server timestamp plus some seconds. Tried again with postman gave the same response.

Any help or suggestion would be appreciated!

Is that your code? Why aren’t you using nem.core to create a transaction?

Here is code that creates a transaction on the testnet: https://github.com/rb2nem/nem_programming/blob/master/code/06/groovy_transfer_transaction.groovy

It is groovy code but straight-forward to translate to java.

1 Like

@BloodyRookie
Hi, I’ve modified the nemcore api a llitle bit cause I’ve given some accounts and wanna test the transaction api. What I’ve been given is public key, private key, address of account. First I didn’t find a way to create a KeyPair object from hexa decimal representation of keys. Reading through rb2’ s code I’m now able to use the nem core api for transaction. Thank you for your attention.