Hi everyone, I have been trying to mint an NFT in aptos testnet from my java spring boot code for a while now. But so far I didn’t found a way to it.
This is the method I tried minting,
I have tried using Aptos APIs given in the following link : [Aptos official doc](https://aptos.dev/nodes/aptos-api-spec/#/)
- I have tried using this API endpoint : encode_submission API from postman. following is the curl command:
curl --location 'https://fullnode.testnet.aptoslabs.com/v1/transactions/encode_submission' \
--header 'Content-Type: application/json' \
--data '{
"sender": "0xed3f5bf8cf96cee66ae304048158712da34b4ff50295634ce27baaa91664eb27",
"sequence_number": "3",
"max_gas_amount": "200000",
"gas_unit_price": "100",
"expiration_timestamp_secs": "1699210949",
"payload": {
"type": "entry_function_payload",
"function": "0x1::aptos_account::transfer",
"type_arguments": [
],
"arguments": [
"0x9a0ff408335d255184813460a4e384b29984e61ca1414d109c78a8bd2f2cf01e","1000"
]
},
"secondary_signers": [
]
}'
which generated this response:
“0x5efa3c4f02f83a0f4b2d69fc95c607cc02825cc4e7be536ef0992df050d9e67c00ed3f5bf8cf96cee66ae304048158712da34b4ff50295634ce27baaa91664eb2704000000000000000200000000000000000000000000000000000000000000000000000000000000010d6170746f735f6163636f756e74087472616e736665720002209a0ff408335d255184813460a4e384b29984e61ca1414d109c78a8bd2f2cf01e08e803000000000000400d0300000000006400000000000000c5e64765000000000200”.
2 . After getting this response I have tried to generate a signature to submit a transaction that is required by this submit_transaction API.
following is the java spring boot code I used to generate signature folloing the instrunctions in encode_submission API docs :
byte[] privateKeyBytes = Hex.decode(ACCOUNT_PRIVATE_KEY);
AsymmetricKeyParameter privateKey = new Ed25519PrivateKeyParameters(privateKeyBytes, 0);
String hexResponse = "0x5efa3c4f02f83a0f4b2d69fc95c607cc02825cc4e7be536ef0992df050d9e67c00ed3f5bf8cf96cee66ae304048158712da34b4ff50295634ce27baaa91664eb2703000000000000000200000000000000000000000000000000000000000000000000000000000000010d6170746f735f6163636f756e74087472616e736665720002209a0ff408335d255184813460a4e384b29984e61ca1414d109c78a8bd2f2cf01e08e803000000000000400d0300000000006400000000000000c5e64765000000000200"; // Replace with the actual hex string
byte[] responseBytes = Hex.decode(hexResponse.substring(2));
// Create the signer
Ed25519Signer signer = new Ed25519Signer();
signer.init(true, privateKey);
byte[] message = responseBytes;
signer.update(message, 0, message.length);
byte[] signature = signer.generateSignature();
// Convert the signature to a Hex string
String hexSignature = Hex.toHexString(signature);
In the above code ACCOUNT_PRIVATE_KEY is my martian wallet account’s private key with ‘0x’ removed.this is the curl command I used to submit the transaction from postman:
curl --location 'https://fullnode.testnet.aptoslabs.com/v1/transactions' \
--header 'Content-Type: application/json' \
--data '{
"sender": "0xed3f5bf8cf96cee66ae304048158712da34b4ff50295634ce27baaa91664eb27",
"sequence_number": "3",
"max_gas_amount": "200000",
"gas_unit_price": "100",
"expiration_timestamp_secs": "1699210949",
"payload": {
"type": "entry_function_payload",
"function": "0x1::aptos_account::transfer",
"type_arguments": [
],
"arguments": [
"0x9a0ff408335d255184813460a4e384b29984e61ca1414d109c78a8bd2f2cf01e","1000"
]
},
"signature": {
"type": "ed25519_signature",
"public_key": "0x202d13f76c5a481945335a2fbbbd422d2af3d0101a3e56dd10dfecbe900d872a",
"signature": "0xd897af9bfcf48e2cb926425d3bdd7b864f3f1dff6354d0d1540fb6e6e223b69b4940810d8ba5d7300231a0f5d01bfcbf65bca4b3c7b434d1bf2937a221d7f30b"
}
}'
but getting this response:
{
“message”: “Invalid transaction: Type: Validation Code: INVALID_SIGNATURE”,
“error_code”: “vm_error”,
“vm_error_code”: 1
}
I have tried asking in discord but got no response so far. If anyone knows how kindly respond.
any help is much appreciated!!!.