How to start the minimal cryptocurrency exchange

How to start the minimal cryptocurrency exchange

Preconditions

Before doing the steps in this guide, please make sure that following software is installed on your machine.

Step 1: Start Docker

Under MacOS once Docker has started you will see the lettering Docker Desktop is running.

/media/mce/en/2021-09-16_01.png

Step 2: Start the container

Run docker-compose up -d in the same directory as the docker-compose.yml file.

Step 3: Fix the BTC testnet

The material of this step is based on this answer (backup PNG).

Step 3.1: Open the shell

To open the shell, click on the icon below in Docker Desktop:

/media/mce/en/2021-12-08_02.png

Thereafter you should see this:

/media/mce/en/2021-12-08_03.png

Step 3.2: Change configuration of the Bitcoin node

Enter the following command in the shell:

vi /root/.bitcoin/bitcoin.conf

Add the following parameter to the file and save it.

peerbloomfilters=1

Enter the following command at the shell:

cat /root/.bitcoin/bitcoin.conf

You should see the following output:

/ # cat /root/.bitcoin/bitcoin.conf
regtest=1
dnsseed=0
upnp=0
server=1
zmqpubrawtx=tcp://0.0.0.0:28332
zmqpubhashblock=tcp://0.0.0.0:28332
whitelist=0.0.0.0/0
txindex=1
addressindex=1
timestampindex=1
spentindex=1
uacomment=bitcore
rpcworkqueue=128
dbcache=16384
rpcallowip=0.0.0.0/0
rpcuser=test
rpcpassword=test

peerbloomfilters=1

[regtesb]
rpcbind=0.0.0.0
port=19000
rpcport=19001

Step 3.3: Restart the Bitcoin node

To do so, press the Restart button in Docker Desktop:

/media/mce/en/2021-12-08_04.png

Step 4: Verify that you can reach the explorer of the BTC testnet

When you enter http://localhost:3002 in your browser, you should see something like this:

/media/mce/en/2021-09-16_02.png

This is the frontend of the BTC Explorer application.

Step 5: Verify that you can reach the frontend of the ETH testnet (Blockscout)

When you enter http://localhost:4000 in your browser, you should see something like this:

/media/mce/en/2021-09-27_01.png

This is the frontend of the Blockscout application.

Step 6: Deploy the USDT contract

In the shell, navigate to the directory erc20/npm-prj. There, run ./deploy-USDT.sh.

This should result in an output like USDT contract deployed to: 0x0B0fA2cC0edd477953D864d8d45c7453c6142802. Write down that address.

Then, navigate to the transactions view in Blockscout at http://localhost:4000/txs. You should see a Token Minting entry.

/media/mce/en/2021-12-19_01.png

Troubleshooting

You will need to install Hardhat for this. In order for the installation to go smoothly, you may need to delete the Hardhat folder from erc20/npm-prj/node_modules/.bin.

Step 7: Set the USDT contract address in the configuration of Camunda

Take the USDT contract address from the previous step and paste it as a value of accounts.eth.usdt.contract-address in file minimal-crypto-exchange/process-engine/src/main/resources/application.yaml:

accounts:
    usdt:
      contract-address: '0x0B0fA2cC0edd477953D864d8d45c7453c6142802'

Step 8: Add ETH to the exchange account

Step 1: Open the geth shell

On MacOS, click on the CLI button in the Docker user interface.

/media/posts/2021-10-09_01.png

Step 2: Start the JavaScript interface

In the geth shell enter geth attach http://localhost:8178.

/media/posts/2021-10-09_02.png

Step 3: Unlock the buffer account

Use the following command where the first argument is the address of the buffer account and the second one is its password.

web3.personal.unlockAccount('0x411167FeFecAD12Da17F9063143706C39528aa28',
'carsdrivefasterbecausetheyhavebrakes', 600);

Step 4: Send the test ETH

Use the code below to send 1 wei of test ETH from the buffer to the exchange account:

eth.sendTransaction({
  from: '0x411167FeFecAD12Da17F9063143706C39528aa28',
  to: '0x190FD61ED8fE0067f0f09EA992C1BF96209bab66',
  value: web3.toWei(1000, 'ether')});

web3.toWei(1000, 'ether') means 1000 ETH.

Please keep the geth shell open as you will need it in the next step.

Step 9: Add ETH to the USDT sender account

This step is analogous to 8. Therefore, I will only provide the commands you need to execute in the geth shell.

Step 1: Unlock the USDT sender account

web3.personal.unlockAccount('0x411167FeFecAD12Da17F9063143706C39528aa28',
'carsdrivefasterbecausetheyhavebrakes', 600);

Step 2: Send the test ETH

eth.sendTransaction({
  from: '0x411167FeFecAD12Da17F9063143706C39528aa28',
  to: '0xDd1e8cC92AF9748193459ADDF910E1b96E88154D',
  value: web3.toWei(1000, 'ether')});

Step 10: Start Camunda

Start the Java application by running the main class com.dpisarenko.minimalcryptoexchange.MinimalCryptoExchangeProcessApplication. Once it has started you can use it as described in the section "How to use Camunda" below.

If you are not familiar with Java, please watch the video How to build and launch Camunda process engine first.



(C) Copyright Dmitrii Pisarenko

Web Site Version 1.110