Atomic swap is a feature to make exchange of cryptocurrencies across different blockchains without trusted third party. Atomic isn't mean instant exchange at one moment but continues process with finished two-sides transactions.
Here is source code of application for automated atomic swap between Minexcoin and Bitcoin blockchains in this repo. All actions of the application are performed automatically with no manual actions. The main thing is configuration needed to run a process.
Keep in mind, atomic swap currently goes on testnet of each cryptocurrency. We are not resposible for running atomic swap on any mainnet!
All configurations appears in main function. Customize it according to your situation and environment.
Let's imagine that we are making atomic swap between Minexcoin and Bitcoin blockchains. Configuration parameters are listed below. There are two parts of configuration - for you (A
) and for your partner (B
). Each of participants should set both but in different order.
In this example A
sends Minexcoin and receives Bitcoins. B
is vise versa.
A
's IP address and port to connect with B
via socket:
selfData.inetAddress(new InetSocketAddress("ddd.ddd.ddd.ddd", dddd));
IP address and port of Minexcoin node RPC:
selfData.nodeAddress(new InetSocketAddress("127.0.0.1", 17788));
Username and password for Minexcoin node RPC:
selfData.nodeLogin("user");
selfData.nodePassword("password");
Port number for ZMQ notification from Minexcoin node:
selfData.notificationPort(1112);
Amount of Minexcoins to send (in satoshi's):
selfData.amount(Coin.valueOf(1000000000));
A
's Minexcoin private key (uncompressed, HEX formatted):
selfData.myKey(ECKey.fromPrivate(new BigInteger("<private_key_here>", 16), false));
B
's Minexcoin public key (uncompressed, HEX formatted):
selfData.otherKey(ECKey.fromPublicOnly(new BigInteger("<public_key_here>", 16).toByteArray()));
Minexcoin worker class instance to work with Minexcoin blockchain:
selfData.worker(MinexCoinWorker.instance());
Amount of confirmations to assume that Minexcoin transaction is mature and amount of confirmations (CSV) to make refund transaction back:
selfData.confirmations(2);
selfData.csv(3);
Partner data configuration is similar except another cryptocurrency blockchain aspects.
B
's IP address and port to connect with A
via socket:
partnerData.inetAddress(new InetSocketAddress("ddd.ddd.ddd.ddd", dddd));
IP address and port of Bitcoin node RPC:
partnerData.nodeAddress(new InetSocketAddress("127.0.0.1", 18332));
Username and password for Bitcoin node RPC:
partnerData.nodeLogin("user");
partnerData.nodePassword("password");
Port number for ZMQ notification from Bitcoin node:
partnerData.notificationPort(1113);
Amount of Bitcoins to receive (in satoshi's):
partnerData.amount(Coin.valueOf(1000000000));
A
's Bitcoin private key (uncompressed, HEX formatted):
partnerData.myKey(ECKey.fromPrivate(new BigInteger("<private_key_here>", 16), false));
B
's Bitcoin public key (uncompressed, HEX formatted):
partnerData.otherKey(ECKey.fromPublicOnly(new BigInteger("<public_key_here>", 16).toByteArray()));
Bitcoin worker class instance to work with Bitcoin blockchain:
partnerData.worker(BitcoinWorker.instance());
Amount of confirmations to assume that Bitcoin transaction is mature and amount of confirmations (CSV) to make refund transaction back:
partnerData.confirmations(2);
partnerData.csv(3);
Application implements Finite State Machine (FSM) based on reactive approach.
To run the FSM you should configure selfDara and partnerData parameters first. You may look at App.java file for example. But use only one case during configuration.
After that create an instance of AtomicSwapFSM:
final FSM<TxState<TxStatus>> fsm = AtomicSwapFSM.create(
selfData, partnerData,
true,
5, TimeUnit.SECONDS,
5, TimeUnit.SECONDS,
1000, "AtomicSwapFSM Event", "AtomicSwapFSM-Task-%d"
);
And finally start the atomic swap process:
fsm.start();