Token swaps happen in two parts.
First is the create_swap cli tool.
./create_swap
Please enter the coin or token you wish to send during the swap
abc
Please enter the amount of coins or tokens to send: (eg. 23.4)
10
Please enter the coin or token you wish to receive during the swap
xyz
Please enter the amount of coins or tokens you expect to receive: (eg. 23.4)
10
Please enter the wallet address of the account you are swapping with.
CLC03f5e69936a5251ba6e1e0530a1dcac41c9d802c5b5fc6179d713dad56d4b46345
Please enter the amount for the first miner tip: (must be at least 1% of token 1)
0.1
Please enter the amount for the second miner tip: (must be at least 1% of token 2)
0.1
Please enter the amount for the fee you will pay: (eg. 1.09)
2
Please enter the amount for the fee other party will pay pay: (eg. 1.09)
2
Please enter how many hours until the offer expires (eg. 72)
72
The create_swap output:
transaction: {
"txtype": 6,
"timestamp": 1711560457,
"offer_expiration": 1711819657,
"ticker1": "abc ",
"value1": 1000000000,
"ticker2": "xyz ",
"value2": 1000000000,
"sender1": "CLC024317262f00570608aabfcdacebc0fe9def7b6529f072b7a5e3a2b68136c984a7",
"sender2": "CLC03f5e69936a5251ba6e1e0530a1dcac41c9d802c5b5fc6179d713dad56d4b46345",
"tip1": 10000000,
"tip2": 10000000,
"txfee1": 200000000,
"txfee2": 200000000,
"hash": "422972e105527b666c32f62059c803b0d092b7dbed174710e498eaea3ab974bd",
"signature1": "fa0c234ac496a98b28840cf6c1a78d6a75b1a5aa1e46811873974bcad55591c25141a141c71fd5022269258905e9087f85914f71776aa16e8f7b19f940cce8cc"
}
Output is also saved to transactions:
ls transactions/
422972e105527b666c32f62059c803b0d092b7dbed174710e498eaea3ab974bd.json
Note the above transaction only has 1 signature but a token swap requires 2 signatures. So at this point user 1 must send the transaction to be signed by user 2.
So the second part of the process is the sign_swap cli tool which is used by user 2.
./tools/sign_swap ./tools/transactions/422972e105527b666c32f62059c803b0d092b7dbed174710e498eaea3ab974bd.json
Are you expecting to receive 10 abc? (yes/no): yes
Are you expecting to send 10 xyz? (yes/no): yes
Are you willing to spend 2 clc in fees? (yes/no): yes
Are you willing to tip 0.1 xyz? (yes/no): yes
The sign_swap output:
Transaction: {
"txtype": 6,
"timestamp": 1711560457,
"offer_expiration": 1711819657,
"ticker1": "abc ",
"value1": 1000000000,
"ticker2": "xyz ",
"value2": 1000000000,
"sender1": "CLC024317262f00570608aabfcdacebc0fe9def7b6529f072b7a5e3a2b68136c984a7",
"sender2": "CLC03f5e69936a5251ba6e1e0530a1dcac41c9d802c5b5fc6179d713dad56d4b46345",
"tip1": 10000000,
"tip2": 10000000,
"txfee1": 200000000,
"txfee2": 200000000,
"hash": "422972e105527b666c32f62059c803b0d092b7dbed174710e498eaea3ab974bd",
"signature1": "fa0c234ac496a98b28840cf6c1a78d6a75b1a5aa1e46811873974bcad55591c25141a141c71fd5022269258905e9087f85914f71776aa16e8f7b19f940cce8cc",
"signature2": "752b6b61f1d697b329f52e6b64c6fc99c5ab038970804b329adbfbb3c6c1e690417fba54681e7d41da4de44af61a06d200219eb95aef98ca4191f483b820f622"
}
Output is also saved to transactions:
ls transactions/
422972e105527b666c32f62059c803b0d092b7dbed174710e498eaea3ab974bd.json
User 2 then has until the expired time is up to broadcast. This prevents abuse of transactions broadcast in the future.
./broadcast_transaction ./transactions/422972e105527b666c32f62059c803b0d092b7dbed174710e498eaea3ab974bd.json