How to encode a signed transaction to submit the transaction in network?

I have tried using this link https://fullnode.testnet.aptoslabs.com/v1/transactions/encode_submission and got this response:

β€œ0x5efa3c4f02f83a0f4b2d69fc95c607cc02825cc4e7be536ef0992df050d9e67c00ed3f5bf8cf96cee66ae304048158712da34b4ff50295634ce27baaa91664eb2704000000000000000200000000000000000000000000000000000000000000000000000000000000010d6170746f735f6163636f756e74087472616e736665720002209a0ff408335d255184813460a4e384b29984e61ca1414d109c78a8bd2f2cf01e08e803000000000000400d0300000000006400000000000000c5e64765000000000101202d13f76c5a481945335a2fbbbd422d2af3d0101a3e56dd10dfecbe900d872a”

In docs:

" To sign a message using the response from this endpoint:

1)Decode the hex encoded string in the response to bytes.
2)Sign the bytes to create the signature.
3)Use that as the signature field in something like Ed25519Signature, which you then use to build a TransactionSignature. "

but I don’t know how to do these? any help is much appreciated.

 byte[] privateKeyBytes = Hex.decode(ACCOUNT_PRIVATE_KEY);
            AsymmetricKeyParameter privateKey = new Ed25519PrivateKeyParameters(privateKeyBytes, 0);

 byte[] responseBytes = Hex.decode(hexResponse.substring(2));
            
            // Create the signer
            Ed25519Signer signer = new Ed25519Signer();
            signer.init(true, privateKey);

            // Sign the message (hashRawTransaction)
//            byte[] message = hashRawTransaction(rawTransaction);
            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 a hex value I got from my martian wallet.

3 Likes

Check the node section

1 Like

You really want to start a class on coding now

1 Like

are you talking about this?

2 Likes