How to Use Atomic Swap
Last updated
Last updated
A is required if you want a third-party to move funds on your behalf. In short, you are allowing them to move your tokens.
In our case, we would like the Orion Exchange contract to trade our ERC20 tokens for us, so we will need to approve an allowance (a certain amount) for this contract to move a certain amount of our ERC20 tokens on our behalf.
When setting the token allowance, make sure to provide enough allowance for the buy or sell amount as well as the gas.
When setting the token allowance, make sure to provide enough allowance for the buy or sell amount as well as the gas; otherwise, you may receive a 'Gas estimation failed' error.
In order to carry out a cross-chain transaction, the first step is to lock your assets on the origin chain. This is achieved by invoking the lockAtomic
method on the Exchange contract. The process involves two main steps described in following sections.
Here is the code snippet to correctly generate secretHash & secret for lockOrder.
This part of the process involves generating a secret hash and secret for the lock order. Here's a Go code snippet that accomplishes this task. This code utilizes the crypto/rand
package from Go's standard library to generate random bytes, and the crypto
package from go-ethereum
to hash the secret.
You can check this code here:
Here is the code snipper to perform lockAtomic
call.
This step involves preparing the lock order payload and then invoking the lockAtomic
function on the smart contract. Here's a Go code snippet that uses the go-ethereum
package to interact with the EVM network. This code snippet essentially constructs a transaction calling the lockAtomic
method on the contract, then signs it with the private key, and finally sends it to the EVM network of your choice.
It's necessary to replace "ExchangeWithAtomicABI"
with the ABI of Exchange contract. Lastly, remember to uncomment the line that sends the transaction if you wish to perform the actual lock operation.
Next step is let Aggregator (Atomic Swap API) know that you've sent lock transaction. This step is crucial to make redeem possible on target chain.
In our example, origin chain is BSC, destination chain is Fantom.
In the given RedeemOrder structure, you also need to replace []byte("signature")
with the actual byte slice signature you received when the redeem order was created. Please remember that the process of generating a proper signature might be quite complex and can require specific cryptographic libraries or tools.