I am running Bitcoin and Litecoin nodes fully synced on testnet.Can I perform atomic swapping by using this networks?
I heard it can be done through HTLC(Hash Time Locked Contracts). How can I do exactly by HTLC and trying to go deeper in to HTLC?
You would need to find another party to do the swap. An example:
Alice and Bob have accounts on both chains. Alice has Litecoin that she wants to exchange into Bitcoin. Bob has Bitcoin that he wants to trade for Litecoin.
Alice tells Bob that she is willing to give him 2.5 Litecoin for 1 Bitcoin. Bob agrees. They both agree that Alice will publish a contract on the Litecoin blockchain that transfers 2.5 Litecoin from Alice to Bob.
Once the Litecoin contract is published, Bob examines it. He sees that the parameters are to his liking, so he publishes a contract on the Bitcoin blockchain that transfers 1 Bitcoin from Bob to Alice.
Alice examines the Bitcoin contract, and likes what she sees. She uses the preimage that she used to build the Litecoin contract to unlock the 1 Bitcoin. Bob is no longer the owner of the 1 Bitcoin.
When Alice used her preimage, that preimage was published on the Bitcoin blockchain. Bob sees it, and uses the same preimage to unlock the 2.5 Litecoin on the Litecoin blockchain.
That example is a simplified version of the typical scenario, but I hope it helps you see the coordination required to do an HTLC.
A little more detail into the mechanisms can be found on a writeup I did for HTLCs between the Bitcoin and Bitshares blockchains. It can be found at http://www.jmjatlanta.com/index.php/2018/09/27/bitshares-and-hashed-time-lock-contracts-htlc
If you are looking for more technical how-to, you can use the following resource:
I use the libbitcoin library for BTC. A tutorial that can get you started with HTLCs using that library can be found at http://aaronjaramillo.org/libbitcoin-cross-chain-swaps-with-htlcs