@radar/htlc
A library used to construct and interact with HTLCs across multiple networks & network models
Installation
npm
yarn
Usage - Bitcoin
Construct a Bitcoin HTLC
Construct a new Bitcoin HTLC with an absolute timelock:
Construct a new Bitcoin HTLC with a relative timelock:
Construct a Bitcoin HTLC from an existing redeem script:
Construct a Bitcoin HTLC with a refund public key instead of address:
Interact with the Bitcoin HTLC
Get the HTLC details:
Get the redeem script:
Generate the fund transaction. You can now broadcast it using sendrawtransaction
:
Generate the claim transaction. You can now broadcast it using sendrawtransaction
:
Generate the refund transaction. You can now broadcast it using sendrawtransaction
:
For working examples, view the Absolute or Relative Timelock Bitcoin HTLC tests.
Usage - Ethereum
Construct an Ethereum HTLC
Asset: Ether
Asset: ERC20
Interact with the Ethereum HTLC
Get the deployed HTLC contract instance:
Generate, sign, and broadcast the fund transaction using the passed provider:
Generate and broadcast the claim transaction using the passed provider:
Generate and broadcast the refund transaction using the passed provider:
Want to pass in additional tx params? Pass all desired tx params as the last argument:
Don't want to sign and broadcast the transaction? Set shouldBroadcast
to false to return the unsigned transaction. You can now broadcast it using eth_sendTransaction
:
For working examples, view the Ether or ERC20 Ethereum HTLC tests.
Usage - Stellar
Construct a Stellar HTLC
Interact with the Stellar HTLC
Build, sign, and broadcast a transaction (envelope) to create an escrow account (escrowPubKey):
Build the fundEnvelope
and refundEnvelope
for the user:
Once the user funds, pay the invoice to get the payment secret. Use the payment secret to claim the funds. Once broadcast, the escrow account gets merged into the server account. Swap Complete.
For a working example, view the Stellar HTLC tests.
Testing
Build container services for tests
Run tests:
Additional Information
Subnet Naming
Subnets should be named SIMNET
, TESTNET
, or MAINNET
if there is only one instance of the subnet type. If there are two or more instances of a single subnet type (multiple testnets, etc.) then the naming convention should be SUBNETNAME_SUBNETTYPE
. e.g. KOVAN_TESTNET
.
Last updated