npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jelly-swap/bitcoin

v0.1.53

Published

JellySwap TypeScript implementation for Bitcoin.

Downloads

1

Readme

Getting started

yarn add @jelly-swap/bitcoin
yarn add @jelly-swap/btc-web-wallet

or

npm install @jelly-swap/bitcoin
npm install @jelly-swap/btc-web-wallet

Setup

import { Providers, Contract, Config, Adapter } from  '@jelly-swap/bitcoin';

Configuration

const  SWAP_EXPIRATION_TIME = 86400; // 1 DAY

const  config = { 
    ...Config(SWAP_EXPIRATION_TIME),
    receiverAddress:  'LIQUIDITY_PROVIDER_ADDRESS',
    providerUrl:  'https://spacejelly.network/btc/api/v1/btc/',
};

BTC Provider

const  provider = new  Providers.BitcoinProvider(config.providerUrl);

BTC Web Wallet

const  mnemonic = 'choose stone donkey wheat pudding gasp harsh pupil sibling post brief afraid';
const  wallet = new  Wallet(mnemonic, provider);

BTC Adapter

const  adapter = new  Adapter(config);

BTC Contract

const  contract = new  Contract(wallet, config);

Initiate a swap

const  userInput = {
	network:  'BTC',
	inputAmount:  '0.01', // BTC amount
	outputNetwork:  'DAI',
	outputAmount:  '84212086000000000000', // DAI amount
	sender:  'bc1q9zh2n6yqun8syggzx6kqlkema5qw9nrz7he90l', // user's BTC address
	outputAddress:  '0x45ce9d7bdadb704c68242118e2b8586e491e5c51', // user's DAI address
	secret:  'film ritual cream paper try search asthma grab admit viable work auction',
};

const  swapInput = adapter.formatInput(userInput);
console.log(swapInput);
{
    network: 'BTC',
    inputAmount: '1000000',
    outputNetwork: 'DAI',
    outputAmount: '84212086000000000000',
    sender: 'bc1q9zh2n6yqun8syggzx6kqlkema5qw9nrz7he90l',
    outputAddress: '0x45ce9d7bdadb704c68242118e2b8586e491e5c51',
    secret: 'film ritual cream paper try search asthma grab admit viable work auction',
    hashLock: '0xee4aad2300d4d8d3f5f58719201ded5a65e00dbda8c3ba0bd066cf3a365e9b73',
    receiver: 'tb1qc4mwllgvmy0xqsdexpm5v8g74ldmv698whnyrw',
    expiration: 1588587562,
};

const  txHash = await  contract.newContract(swapInput);

Subscribe

contract.subscribe(callback, {
    new: {
	    type:  'getSwapsByAddressAndBlock',
	    address:  'USER_ADDRESS', 
    },
    withdraw: {
	    type:  'getWithdrawByReceiverAndBlock',
	    address:  'USER_ADDRESS',
    },
});

const  callback = (event) => {

console.log(event);

{
    eventName: 'NEW_CONTRACT',
    network: 'BTC',
    inputAmount: 5604499,
    outputNetwork: 'DAI',
    outputAmount: '2398272000000000000',
    sender: 'bc1q7fnkalepy69yuh5f5axrzt4xyz8dxwwwxcwfxk',
    isSender: true,
    outputAddress: '0xdf9cb34d9dd92d54cec4150bd1518202e391479c',
    receiver: 'bc1qwjeylyfrkn8sckwux789dqtscafujhgy4xcddg',
    refundAddress: 'bc1q7fnkalepy69yuh5f5axrzt4xyz8dxwwwxcwfxk',
    id: '0x4a04b233272a95a01827a099becc3136899cdc0a0c0c9b32b7c705ee6644ff3f',
    transactionHash: '03cad639ffb7880b9cd62794f91517865526db9d084a7e3b4b1c3cba6c98d956',
    status: 1,
    expiration: 1588651138,
    blockHeight: 628836,
    hashLock: '0xbb380eead9fa13e6388a245397950995ce72093d1d5ebe0b19ecc8767b0e1a40',
};

{
    eventName: 'WITHDRAW',
    network: 'BTC',
    id: '0x4a04b233272a95a01827a099becc3136899cdc0a0c0c9b32b7c705ee6644ff3f',
    transactionHash: 'b58a0ea14b58319d589d0a2b740715ec2d036bd67bac257eb8e78b663e9943e7',
    secret: '0x357bce78906a196afc7089c3005134bbca0b09d876e8e3c911427579fa8c2f3e',
    hashLock: '0xbb380eead9fa13e6388a245397950995ce72093d1d5ebe0b19ecc8767b0e1a40',
    sender: 'bc1q7fnkalepy69yuh5f5axrzt4xyz8dxwwwxcwfxk',
    receiver: 'bc1qwjeylyfrkn8sckwux789dqtscafujhgy4xcddg',
    blockHeight: 628849,
};

Get Past Events

  const  type = 'new' || 'withdraw';
  const  pastEvents = await  contract.getPastEvents(type, {
  	    new: { 
  		    type:  'getSwapsByAddress',
  		    address:  'USER_ADDRESS',   
  	    },
  	    withdraw: {
  		    type:  'getWithdrawByReceiver',
  		    address:  'USER_ADDRESS',
  	    },
  });

console.log(pastEvents);

New Contract

[
    {   
    network:  'BTC',
    inputAmount:  5604499,
    outputNetwork:  'DAI',
    outputAmount:  '2398272000000000000',
    sender:  'bc1q7fnkalepy69yuh5f5axrzt4xyz8dxwwwxcwfxk',
    isSender:  true,
    outputAddress:  '0xdf9cb34d9dd92d54cec4150bd1518202e391479c',
    receiver:  'bc1qwjeylyfrkn8sckwux789dqtscafujhgy4xcddg',
    refundAddress:  'bc1q7fnkalepy69yuh5f5axrzt4xyz8dxwwwxcwfxk',
    id:  '0x4a04b233272a95a01827a099becc3136899cdc0a0c0c9b32b7c705ee6644ff3f',
    transactionHash:  '03cad639ffb7880b9cd62794f91517865526db9d084a7e3b4b1c3cba6c98d956',
    hashLock:  '0xbb380eead9fa13e6388a245397950995ce72093d1d5ebe0b19ecc8767b0e1a40',
    status:  1,
    expiration:  1588651138, 
    blockHeight:  628836,
    },
    ...
];

Withdraw

[
    {
	    network: 'BTC',
	    id: '0x4a04b233272a95a01827a099becc3136899cdc0a0c0c9b32b7c705ee6644ff3f',
	    transactionHash: 'b58a0ea14b58319d589d0a2b740715ec2d036bd67bac257eb8e78b663e9943e7',
	    secret: '0x357bce78906a196afc7089c3005134bbca0b09d876e8e3c911427579fa8c2f3e',
	    hashLock: '0xbb380eead9fa13e6388a245397950995ce72093d1d5ebe0b19ecc8767b0e1a40',
	    sender: 'bc1q7fnkalepy69yuh5f5axrzt4xyz8dxwwwxcwfxk',
	    receiver: 'bc1qwjeylyfrkn8sckwux789dqtscafujhgy4xcddg',
	    blockHeight: 628849,
    },
    ....
]