xiaoyuz --> Hi support team, Iām trying to build request for transaction in Java, all goes like near-js-api does, and use borshj to serialize objects, but got response āFailed to decode transaction: Unexpected length of inputā, what does that mean? The request body as below:
{
ājsonrpcā: ā2.0ā,
āmethodā: ābroadcast_tx_asyncā,
āparamsā: [
āPZUpvwvXjTTJEWqOk3ekv4wBc6UKEsFMjF864RdMC36YfIxu0FYs3IArHO/A/0D5uv7OOHpj2dab0rTQWAuyCAABAAAAAAAAoe3MzhvC0wAAAAAAALWm6qYyDoHqQycG/IZ7W6W1/BJx/Q1E98PqOGfSIexqAQAAALV3+KuecGdGSKsEyDZkTx5uRs2gB2YbyaPgjVJVIKeQAEAAAABiNTc3ZjhhYjllNzA2NzQ2NDhhYjA0YzgzNjY0NGYxZTZlNDZjZGEwMDc2NjFiYzlhM2UwOGQ1MjU1MjBhNzkwQAAAAGI1NzdmOGFiOWU3MDY3NDY0OGFiMDRjODM2NjQ0ZjFlNmU0NmNkYTAwNzY2MWJjOWEzZTA4ZDUyNTUyMGE3OTA=ā
],
āidā: 1
}
Response as:
{
ājsonrpcā: ā2.0ā,
āerrorā: {
ānameā: āREQUEST_VALIDATION_ERRORā,
ācauseā: {
ānameā: āPARSE_ERRORā,
āinfoā: {
āerror_messageā: āFailed to decode transaction: Unexpected length of inputā
}
},
ācodeā: -32700,
āmessageā: āParse errorā,
ādataā: āFailed to decode transaction: Unexpected length of inputā
},
āidā: 1
}
bucanero --> I donāt know about Java, but have you tried building the same exact transaction with near-api-js, and compare the serialized output?
xiaoyuz --> This is my signedTx structure:
SignedTransactionStruct{transaction=TransactionStruct{signerId=āb577f8ab9e70674648ab04c836644f1e6e46cda007661bc9a3e08d525520a790ā, publicKey=PublicKey{keyType=0, data=[-75, 119, -8, -85, -98, 112, 103, 70, 72, -85, 4, -56, 54, 100, 79, 30, 110, 70, -51, -96, 7, 102, 27, -55, -93, -32, -115, 82, 85, 32, -89, -112]}, nonce=1, receiverId=āb577f8ab9e70674648ab04c836644f1e6e46cda007661bc9a3e08d525520a790ā, actions=[Action{transfer=Transfer{deposit=1000000000000000000000000}}], blockHash=[-75, -90, -22, -90, 50, 14, -127, -22, 67, 39, 6, -4, -122, 123, 91, -91, -75, -4, 18, 113, -3, 13, 68, -9, -61, -22, 56, 103, -46, 33, -20, 106]}, signature=Signature{keyType=0, data=[61, -107, 41, -65, 11, -41, -115, 52, -55, 17, 106, -114, -109, 119, -92, -65, -116, 1, 115, -91, 10, 18, -63, 76, -116, 95, 58, -31, 23, 76, 11, 126, -104, 124, -116, 110, -48, 86, 44, -36, -128, 43, 28, -17, -64, -1, 64, -7, -70, -2, -50, 56, 122, 99, -39, -42, -101, -46, -76, -48, 88, 11, -78, 8]}}
xiaoyuz --> Yes Iāve compared the two but they were different. Also Iāve read the code of borshj and borsh-js, and found it seems that their ways of serialize an object are a bit of different. Furthermore, there is a bug in borshj that when serialize byte array then an error will occur, and someone has raised an issue https://github.com/near/borshj/issues/4 but not fixed yet.
bucanero --> oh well if the serializer has discrepancies that could be the cause of your issues. If possible, Iād try to:
serialize a sample transaction using borsh-js
get the serialized output
use that output in your Java code, and see if it works. If your java code works using the serialized data created with borsh-js, then your issue is the borshj library.