# Sending a MAN transaction(Java + Maven), Intermediate level

**by Delbypoc**

\ <br>

This tutorial is for educational purposes only, I’m not responsible for any losses, damages, or other liabilities which may occur by using any info/code provided here(or anywhere else it is posted).

!\[Text

Description automatically generated]\(<https://www.matrix.io/gitbook/Guides/Guides_05.fld/image001.png>)

I’m under no circumstances a Java/Maven professional (or an Java/Maven Expert)!

The code is not production ready! (only for learning purposes)

In this guide, I’m going to show you how to send a MAN transaction (Mainnet) using Java + Maven.

We will make use of the following dependencies (+ GSON):

!\[Text

Description automatically generated]\(<https://www.matrix.io/gitbook/Guides/Guides_05.fld/image002.png>)

They have to be added in the pom.xml file(you can find more info about it on [**https://maven.apache.org/guides/introduction/introduction-to-the-pom.html**](https://maven.apache.org/guides/introduction/introduction-to-the-pom.html), you can find those dependencies on maven repository [**https://mvnrepository.com/search?q=io.github.matrixainetwork**](https://mvnrepository.com/search?q=io.github.matrixainetwork))

Let’s start coding:

I will initialize a provider first (I will pass in a public node of Matrix for use):

![](https://www.matrix.io/gitbook/Guides/Guides_05.fld/image003.png)

After that, we are going to start by declaring some of the variables we are going to use for the transaction, we will need the following, the variable names should be self-explanatory: privateKey, addressWeSendFrom, addressWeSendTo, gasLimit, value (which is the amount we are going to send), chainId, unixTime (not mandatory):

!\[Text

Description automatically generated]\(<https://www.matrix.io/gitbook/Guides/Guides_05.fld/image004.png>)

We are going to get the nonce (which is the number of transactions a specific address have):

!\[Text

Description automatically generated]\(<https://www.matrix.io/gitbook/Guides/Guides_05.fld/image005.png>)

Then we are going to get the gas price:

!\[Text

Description automatically generated]\(<https://www.matrix.io/gitbook/Guides/Guides_05.fld/image006.png>)

And the balance (so we can print it in console, MAN Denomination):

!\[Text

Description automatically generated]\(<https://www.matrix.io/gitbook/Guides/Guides_05.fld/image007.png>)

Then we are going to create a Credentials object and initialize it with our private key:

![](https://www.matrix.io/gitbook/Guides/Guides_05.fld/image008.png)

Now we are going to make a list that has the extra\_to field format:

!\[Text

Description automatically generated]\(<https://www.matrix.io/gitbook/Guides/Guides_05.fld/image009.png>)

It should look like this in JSON format:

!\[Diagram

Description automatically generated]\(<https://www.matrix.io/gitbook/Guides/Guides_05.fld/image010.png>)

Now we are going to build the RawTransaction by using the parameters we initialized earlier (also sign it):

!\[Text

Description automatically generated]\(<https://www.matrix.io/gitbook/Guides/Guides_05.fld/image011.png>)

After the Raw transaction is built, we can send it and print the hash/pretty-print the transaction object in the console (I’m going to pretty print by using the GSON library, [**https://mvnrepository.com/artifact/com.google.code.gson/gson**](https://mvnrepository.com/artifact/com.google.code.gson/gson)):

!\[Text

Description automatically generated]\(<https://www.matrix.io/gitbook/Guides/Guides_05.fld/image012.png>)

convertObjToString function for pretty print:

!\[Text

Description automatically generated]\(<https://www.matrix.io/gitbook/Guides/Guides_05.fld/image013.png>)

byteToHex function used for RawTransaction:

!\[Text

Description automatically generated]\(<https://www.matrix.io/gitbook/Guides/Guides_05.fld/image014.png>)

Sample output:

!\[Text

Description automatically generated]\(<https://www.matrix.io/gitbook/Guides/Guides_05.fld/image015.png>)

After running the program, the transaction will get broadcasted via the provider node we used.

Github code:

[**https://github.com/CognitiveProcessing/Matrix-AI-Network-Code-Snippets/blob/main/Java/SendManTransaction.java**](https://github.com/CognitiveProcessing/Matrix-AI-Network-Code-Snippets/blob/main/Java/SendManTransaction.java)

Also, check out the official Matrix AI Network Developer Portal:

[**dev.matrix.io**](https://www.matrix.io/blog/dev.matrix.io)

&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.matrix.io/guides/sending-a-man-transaction-java-+-maven-intermediate-level.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
