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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@hydro-protocol/swap-sdk

v1.0.5

Published

Javascript SDK for Hydro Swap

Readme

Javascript SDK for Hydro Swap

Provides more advanced integration for the Hydro Swap widget when a simple script tag embed is not enough.

What is Hydro Swap?

Hydro Swap allows for easy conversion between ETH and ERC20 tokens. The Hydro Swap API will calculate a current market price for an ERC20 token and allow you to exchange ETH/tokens at that price point. The price point is fluid and the offer is only valid for a set period of time. Because of that, you must interact with the Hydro Swap API to create and sign an order validating the amount of token and price. Once you have the signed transaction data it can be passed to this contract to complete the transaction.

For more information, please visit https://swap.hydroprotocol.io/

What is this SDK for?

The SDK is meant to help you construct and embed the Swap Widget if you would like more advanced functionality, such as the ability to implement a custom wallet.

Getting started

To get started, simply install the package through npm:

npm i @hydro-protocol/swap-sdk

Once you've done that you can begin customizing your widget.

HydroSwap

The HydroSwap class is the main interface for customizing your widget. You can use it as follows:

import HydroSwap from "@hydro-protocol/swap-sdk";

const sdk = new HydroSwap("<id>");

The ID you use will be assigned to you when you create your Hydro Swap account and set up your market.

Once you have the SDK, you can set various properties for the widget. These calls are chainable.

setDefaultAmount(amount: number)

This sets the default amount that will be populated into the token field when the widget loads.

setWallets(wallets: Wallet[])

This sets a list of wallets that will be available via the wallet selection dropdown in the widget. Currently acceptable wallets are "metamask", "ledger", and "custom".

setDefaultWallet(wallet: Wallet)

This sets which wallet in the dropdown will be selected by default on load.

setCustomWallet(customWallet: CustomWallet)

If you pass "custom" as one of your wallets in setWallets, you must define a handler for your wallet in the form of a CustomWallet. See next section for details.

attach(container: HTMLElement)

Attaches the swap widget into your document, with the container as the parent element.

CustomWallet

The CustomWallet class is used to define a handler for a custom wallet. You can use it as follows:

import { CustomWallet } from "@hydro-protocol/swap-sdk";

const customWallet = new CustomWallet("Custom Wallet");

The custom wallet takes in multiple parameters in the constructor.

constructor(name: string, iconURL?: string)

You must define a name for your custom wallet, which will be displayed in the dropdown. If you don't define an icon we will provide a default for you. If you'd like to define an icon, you must pass a string as the second argument of the constructor. This string can be anything that would go into an img tag as the src. e.g. a URL to a hosted image, or a data:image string.

Beyond the constructor, you must define 3 handlers for your wallet.

handleGetAccounts(getAccounts: () => Promise<string[]>)

This lets you define a function that will return a promise. The promise should resolve to a list of account addresses that are handled by this wallet.

handleApproveTransaction(approveTransaction: (txData: Tx) => Promise<boolean>)

This lets you define a function that will take web3 transaction data and return a promise. It will be called when you should decide if you want to allow the transaction to go through. Most commonly you will provide some UI to the user who will then decide if they want to sign and send this transaction to the blockchain. The promise should resolve to true if you want the transaction to proceed, and false if not.

handleSignTransaction(signTransaction: (txData: Tx) => Promise<string>)

This lets you define a function that will take web3 transaction data and return a promise. The promise should resolve to a string, which will be the raw signed transaction data in hex format.

Example

A full example of how you might customize and insert the Hydro Swap widget.

import HydroSwap, { CustomWallet } from "@hydro-protocol/swap-sdk";

const customWallet = new CustomWallet(
  "Custom Wallet",
  "https://example.com/custom_wallet.png"
)
  .handleApproveTransaction(async txData =>
    window.confirm("Approve transaction from: " + txData.from)
  )
  .handleGetAccounts(async () => [this.wallet.getAddress()])
  .handleSignTransaction(async txData => this.wallet.sign(txData));
const sdk = new HydroSwap("<id>")
  .setDefaultAmount(100)
  .setWallets(["metamask", "custom"])
  .setDefaultWallet("custom")
  .setCustomWallet(customWallet);
sdk.attach($("#hydro-swap-container"));