So you want to list Tezos in your exchange?

0
210

A step by step guide to integrate Tezos to your system

Tezos is on the news! And it’s a robust project that is here to stay for many years to come. Very competent people have been working hard, building its foundations since mainnet launch. Now the results begin to show up.

Suddenly, everybody is talking about Tezos on social media and asking their favorite crypto exchanges to add Tezos to their portfolio.

This article will show how easy it is to add Tezos to your exchange listings.

Step 1 — Choose a computer language

Nowadays there are many options regarding computer languages to develop software. For sure your exchange already has a language of choice and your development team has a culture of building things and integrating systems with that language.

Step 2— Choose a library

The easiest way to integrate Tezos to your systems is to use a library. All the complexity of interacting with Tezos blockchain was already embedded into the code by the library developers. This means that a set of methods and functions have already been built to access Tezos blockchain and your delevopment team will be pleased to use them, as they will make the work a lot simpler.

Nevertheless, which library you will use, depends on the computer language you chose in step 1. Here is a list of the current Tezos libraries available (according to developers.tezos.com) and their correspondent language:

+-------------------+-----------------------+
| Library | Language |
+-------------------+-----------------------+
| Taquito | TypeScript |
| ConseilJS | Node.js/Javascript |
| ConseilPy | Python |
| TezosKit | Swift |
| PyTezos | Python |
| Eztz | Javascript |
| TezBridge | Web application |
| Go-Tezos | GoLang |
| AirGap-Coin-Lib | Node.js/Javascript |
| TezosJ_SDK | Android Java |
| TezosJ_plainJava | Java |
| Netezos | .NET |
+-------------------+-----------------------+

For this first part of this tutorial, we are going to use the TezosJ_plainJava library, designed to integrate Tezos to other systems by using default Java language. There are already a reasonable number of exchanges using TezosJ_SDK as their preferred integration tool.

We are going to use Eclipse IDE to create a simple Tezos wallet with short examples.

Step 3 — Setting up a wallet test project

Open Eclipse IDE. You should see a screen like this:

Eclipse IDE start screen

Select menu File -> New -> Project:

In the Select a wizard window, choose Gradle Project and then click Next button twice:

Now just set the project name to TezosWallet and click Finish button:

Wait for Eclipse to create the project with all the needed files. It may take a little while as it will download them from bintray.

You should now have a project structure like this:

Perfect. Now we are going to add our Java JAR library file. Go to Tezos.Rio github repository and download file tezosj-sdk-plain-java-1.0.9.jar

On your file explorer, copy the tezosj-sdk-plain-java-1.0.9.jar file (CTRL+C).

Go back on Eclipse click on the name of the project and Paste with CTRL+V.

The file will appear as added to the project structure:

Now just click once with the right mouse button over the tezosj-sdk-plain-java-1.0.9.jar file and choose Build Path -> Add to Build Path:

All set. Now we are ready to start building our own Tezos wallet.

Lets create our Main class. Right-click on src/main/java and choose New -> Class:

Type Main as the name of the class, check “public static void Main” then press Finish button:

All right. Now we have all the project set up. Nevertheless, if you run the project (choosing Main as the launch class), nothing will show up on the Console:

So, lets start the fun by instantiating the TezosWallet class.

In Main class, type:

TezosWallet wallet = new TezosWallet("passphrase");

You will notice that Eclipse won’t recognize at first the TezosWallet class:

Just click on the TezosWallet class reference and select the option to import the class:

You will have to surround it with try-catch too. Just copy and paste the code below to your Main class:

        try
{
TezosWallet wallet = new TezosWallet("passphrase");
}
catch (Exception e)
{
e.printStackTrace();
}

Now, if you run your project, you will see some action. Nevertheless, nothing yet very useful. So, lets make something important appear on the Console. Change the code to look like this:

try
{
TezosWallet wallet = new TezosWallet("passphrase");
System.out.println("PubKey hash:" + wallet.getPublicKeyHash());
System.out.println("Mnemonic : " + wallet.getMnemonicWords());
System.out.println("Balance : " + wallet.getBalance());
}
catch (Exception e)
{
e.printStackTrace();
}

Run the project again. You will get a far more interesting result now:

And voilà! You’ve got a real Tezos wallet ready to make transactions on the mainnet! Could not be easier than that!

Note that, now that you have the mnemonics and the passphrase, you can build the wallet by using a different class constructor, like this:

TezosWallet wallet = new TezosWallet("manual avoid finger target drive badge trip involve blind myself main inspire bird romance face", "passphrase");

Just try it out and you will see that the address wil always be tz1Ps7QuQ5wjiMVeDSpt9u28hRGWCWJmAvK8 with those parameters.

Now that we have a proper functional wallet, lets play around.

Sending some tez to another address:

BigDecimal amount = new BigDecimal("0.123456");
BigDecimal fee = new BigDecimal("0.00294");
JSONObject jsonObject = wallet.send(wallet.getPublicKeyHash(), "tz1ToAddress", amount, fee, "", "");
System.out.println(jsonObject.get("result"));

Saving the wallet to disk:

wallet.save("c:\\temp\\mySavedWallet.txt");

Loading from disk a previously saved wallet:

TezosWallet myLoadedWallet = new TezosWallet(true, "c:\\temp\\mySavedWallet.txt", "passphrase");

Origination operation:

BigDecimal fee = new BigDecimal("0.001300");
BigDecimal amount = new BigDecimal("2");
JSONObject jsonObject = wallet.originate(wallet.getPublicKeyHash(), true, true, fee, "", "", amount, "", "");
System.out.println(jsonObject.get("result"));

Delegation operation:

BigDecimal fee = new BigDecimal("0.001300");
JSONObject jsonObject = wallet.delegate("kt1_delegatorAddress", "tz1_delegate_address", fee, "", "");
System.out.println(jsonObject.get("result"));

Lets put it all together with many other important features, like batch payments, blockchain result waiting, etc, in this full example:

// Creates a new wallet with a passphrase.
TezosWallet wallet = new TezosWallet("myPassphrase");

// Or... creates (imports) a new wallet with its keys.
// TezosWallet wallet = new TezosWallet(privateKey, publicKey, publicKeyHash, myPassphrase);

// Or... imports a previously owned wallet with mnemonic words and passphrase.
// TezosWallet wallet = new TezosWallet("word1, word2, word3, ... word15 ", "myPassphrase");

// Some environment configuration.
// wallet.setIgnoreInvalidCertificates(false);
// wallet.setProxy("", "");

// Shows some wallet data output.
System.out.println(wallet.getMnemonicWords());
System.out.println(wallet.getPublicKeyHash());
System.out.println(wallet.getBalance());

// Saves the current wallet from memory to file.
wallet.save("c:\\temp\\mySavedWallet.txt");

System.out.println("Saved the wallet to disk.");

// Creates a new wallet by reading from file.
TezosWallet myLoadedWallet = new TezosWallet(true, "c:\\temp\\mySavedWallet.txt", "myPassphrase");

System.out.println("Loaded the wallet from disk:");

// Shows loaded wallet data.
System.out.println(myLoadedWallet.getMnemonicWords());
System.out.println(myLoadedWallet.getPublicKeyHash());
System.out.println(myLoadedWallet.getBalance());

// Example of Sending funds.
// BigDecimal amount = new BigDecimal("0.123456");
// BigDecimal fee = new BigDecimal("0.00294");
// JSONObject jsonObject = wallet.send("tz1FromAddress", "tz1ToAddress", amount, fee, "", "");
// System.out.println(jsonObject.get("result"));

// Using Conseil Gateway, from Cryptonomic.
// ConseilGateway cg = new ConseilGateway(new URL("<URL>"), "<APIKEY>", "alphanet");

// Example of origination operation.
// BigDecimal fee = new BigDecimal("0.001300"); // Needed fee for origination.
// BigDecimal amount = new BigDecimal("2"); // Starting new kt1_delegator address balance.
// JSONObject jsonObject = wallet.originate(wallet.getPublicKeyHash(), true, true, fee, "", "", amount, "", "");
// System.out.println(jsonObject.get("result"));

// Example of delegation operation.
// BigDecimal fee = new BigDecimal("0.001300");
// JSONObject jsonObject = wallet.delegate("kt1_delegatorAddress", "tz1_delegate_address", fee, "", "");
// System.out.println(jsonObject.get("result"));

// Example of undelegation operation.
// BigDecimal fee = new BigDecimal("0.001300");
// JSONObject jsonObject = wallet.undelegate("kt1_delegatorAddress", fee);
// System.out.println(jsonObject.get("result"));

// Tools

// Routine to extract the publicKey from a privateKey.
// String mySecretKey = "edsk...";
// String publicKey = Crypto.getPkFromSk(mySecretKey);
// System.out.println(publicKey);


// Batch transactions.

// Example of sending batch transactions.

// Clears the transactions batch.
// wallet.clearTransactionBatch();

// Adds a first transaction to the batch.
// wallet.addTransactionToBatch("from_address", "to_address", new BigDecimal("1"), new BigDecimal("0.00294"));

// Adds a second transaction to the batch.
// wallet.addTransactionToBatch("from_address", "to_address", new BigDecimal("2"), new BigDecimal("0.00294"));

// Adds a third transaction to the batch.
// wallet.addTransactionToBatch("from_address", "to_address", new BigDecimal("3"), new BigDecimal("0.00294"));

// Note that "from_address" above maybe the manager address or its originated kt1 addresses.

// Gets a list of wallet's current (pending) batch transactions.
// ArrayList<BatchTransactionItem> myBatchTransactionsList = new ArrayList<BatchTransactionItem>();
// myBatchTransactionsList = wallet.getTransactionList();

// Sends all transactions in the batch to the blockchain and clears the batch.
// JSONObject jsonObject = wallet.flushTransactionBatch();
// Or... Specifying gasLimit and storageLimit:
// JSONObject jsonObject = wallet.flushTransactionBatch("15400","300");
// System.out.println("Batch transaction sent! Returned operation hash is: ");
// System.out.println(jsonObject.get("result"));


// Synchronously waits for previous operation to be included in a block after sending another one.
// (this is to be used if you need to send a sequence of single transactions, having to wait first for each one to be included).

// BigDecimal amount = new BigDecimal("0.02");
// BigDecimal fee = new BigDecimal("0.00294");
// JSONObject jsonObject = wallet.send("tz1FromAddress", "tz1ToAddress", amount, fee, "", "");
// String opHash = (String) jsonObject.get("result");
// Boolean opHashIncluded = wallet.waitForResult(opHash, numberOfBlocksToWait);
// System.out.println(opHashIncluded);
// Now it is safe to send another transaction at this point.

You can get more details about TezosJ_SDK_plainJava library by browsing its github repository, at https://github.com/TezosRio/TezosJ_plainJava

This tutorial shows how simple it might be to build and integrate Tezos wallets to exchange systems, web sites, games and so on.

In the following chapters we will se how to do the same thing with other libraries. Stay tuned!

PyTezos tutorial : https://baking-bad.github.io/pytezos/


So you want to list Tezos in your exchange? was originally published in Coinmonks on Medium, where people are continuing the conversation by highlighting and responding to this story.