crosschain-atom-swap
v1.0.1
Published
This npm package provides a library for facilitating cross-chain atomic swaps, allowing users to exchange assets between different blockchain networks trustlessly and securely.
Downloads
4
Readme
Cross-Chain Atomic Swap Library
This npm package provides a library for facilitating cross-chain atomic swaps, allowing users to exchange assets between different blockchain networks trustlessly and securely.
Installation
To install this package, use the following command:
npm install crosschain-atom-swap
Usage
Here's how to use the package in your project:
const AtomicSwap = require('crosschain-atom-swap');
// Initialize the atomic swap library
const atomicSwap = new AtomicSwap();
// Example: Initiate a swap between two blockchain networks
const sendingChain = 'Bitcoin';
const receivingChain = 'Ethereum';
const sendingAsset = 'BTC';
const receivingAsset = 'ETH';
const sendingAmount = 0.1; // BTC
const receivingAmount = 1; // ETH
const expirationTime = new Date('2024-04-30T23:59:59Z');
const swapTransaction = atomicSwap.initiateSwap(sendingChain, receivingChain, sendingAsset, receivingAsset, sendingAmount, receivingAmount, expirationTime);
// Example: Claim a swap initiated by the counterparty
const hashlock = swapTransaction.hashlock;
const secret = 'your_secret'; // Replace with the secret shared by the counterparty
const receivingAddress = '0xYourReceivingAddress'; // Replace with your receiving address
atomicSwap.claimSwap(hashlock, secret, receivingAddress);
// Example: Refund a swap if it expires without being claimed
const expiredHashlock = 'expired_hashlock'; // Replace with the hashlock of the expired swap
atomicSwap.refundSwap(expiredHashlock);
Replace the usage examples with your specific requirements and use cases for cross-chain atomic swaps.