@moosty/lisk-htlc
Version:
Hashed Time Lock Contract transaction for Lisk SDK based blockchain applications
129 lines (106 loc) • 5.67 kB
Markdown
[](https://travis-ci.org/moosty/lisk-htlc)
[](https://codecov.io/gh/moosty/lisk-htlc/list/master/)
[](https://david-dm.org/moosty/lisk-htlc)
[](https://deepscan.io/dashboard#view=project&tid=7455&pid=9545&bid=125748)
[](https://github.com/liskhq/lisk-sdk/)
[](http://www.gnu.org/licenses/gpl-3.0)
Simpely add this transaction to your Lisk SDK based blockchain application.
It allows for atomic swap between other blockchains that allow atomic swap by using Hash Time Locked Contracts.
**This is by no means meant to support the production phase yet.**
Send an amount of token, from your wallet on a blockchain application made with the Lisk SDK, to a hash time locked contract
using this custom transaction `HTLC-transaction`. After successfully completing the `HTLC-Transaction` the amount will be
locked inside the contract wallet. To redeem the locked amount, the recipient can unlock the HTLC by sending the `HTLC-transaction`
to the contract wallet with the secret included. If the secret is valid and the transaction is not timed out, the locked funds in
the contract wallet will be send to the recipient wallet.
If the contract is expired, the initial creator of the contract can send a refund `HTLC-transaction` to the contract wallet
and will receive the funds minus the initial fees back.
`npm install --save @moosty/lisk-htlc`
or
`yarn add @moosty/lisk-htlc`
Register the transaction to your blockchain application.
```javascript
import { HTLCTransaction } from '@moosty/lisk-htlc';
App.registerTransaction(HTLCTransaction);
```
Configure the transaction fee and register the HTLC-transaction to your blockchain application.
```javascript
import { UnConfigureHTLCTransaction } from '@moosty/lisk-htlc';
const HTLCTransaction = UnConfigureHTLCTransaction({ fee: '500000000' });
App.registerTransaction(HTLCTransaction);
```
The HTLC transaction is a combination of three sub-transactions.
1. Lock contract transaction
2. Redeem contract transaction
3. Refund contract transaction
```javascript
import { HTLCTransaction } from '@moosty/lisk-htlc';
const LockContractTransaction = new HTLCTransaction({
"passphrase": string, // string passphrase from senderId
"type": 199,
"timestamp": number,
"asset": {
"time": number,
"recipientPublicKey": "", // string recipient publicKey
"type": "", // string [ OP_HASH160 | OP_HASH256 ]
"data": "", // string preimage hash
"secretLength": number, // number length preimage
"amount": "", // string amount to be locked
},
"networkIdentifier": "" // string network Identifier
});
// broadcast LockContractTransaction.toJSON() to blockchain application nodes
```
```javascript
import { HTLCTransaction } from '@moosty/lisk-htlc';
const RedeemContractTransaction = new HTLCTransaction({
"passphrase": string, // string passphrase from recipientId
"type": 199,
"timestamp": number,
"asset": {
"contractId": "", // string contractId
"secret": "", // string preimage
},
"networkIdentifier": "" // string network Identifier
});
// broadcast RedeemContractTransaction.toJSON() to blockchain application nodes
```
```javascript
import { HTLCTransaction } from '@moosty/lisk-htlc';
const RefundContractTransaction = new HTLCTransaction({
"passphrase": string, // string passphrase from senderId
"type": 199,
"timestamp": number,
"asset": {
"contractId": "", // string contractId
"data": "", // string preimage
},
"networkIdentifier": "" // string network Identifier
});
// broadcast RefundContractTransaction.toJSON() to blockchain application nodes
```
```
- [X] Configurable fee amount
- [ ] Better determanistic time lock
- [ ] Documentation
- [ ] Live chain tests
```
The `HTLC-transaction` functions as a interoperability option to transfer tokens between different blockchain applications.
The transaction can facilitate Atomic Swaps between different blockchain tokens. To help better adoption of this transaction
we are building a decentralized exchange to help connect users from different blockchain applications. Atomic Swap between
your Lisk SDK based blockchain application and Bitcoin, Ethereum or any other Lisk SDK based blockchain with the
`lisk-htlc` transaction is coming soon with [Mercator.network](https://mercator.network).
Copyright © 2019 - 2020 Moosty Team
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.