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 🙏

© 2025 – Pkg Stats / Ryan Hefner

gte-typescript-sdk

v0.1.0

Published

TypeScript/React SDK for GTE MegaETH AMM swaps

Downloads

7

Readme

GTE TypeScript SDK (MegaETH Testnet)

A lightweight React-friendly TypeScript SDK that mirrors the gte-python-sdk surface needed for AMM swaps on MegaETH testnet. It wraps the public REST API plus minimal on-chain helpers so a dApp can fetch markets, price tokens, and build approval/swap transactions that follow Uniswap/PancakeSwap v2 conventions.

Features

  • ✅ Network config helper (getChainConfig) derived from the Python SDK/testnet docs.
  • ✅ Typed REST client for /markets, /tokens, and /markets/{id}/{book|trades|candles} (pairs, TVL, prices, orderbooks, trades, candles).
  • ✅ Portfolio endpoint (/users/{address}/portfolio) to render wallet balances in USD.
  • ✅ On-chain quoting via the MegaETH Uniswap v2 router (getQuote, getQuoteExactOut).
  • ✅ Transaction builders for ERC-20 approvals and swap flows (buildApprove, buildSwapExactIn, buildSwapExactOut).
  • ✅ Works in React (fetch + viem under the hood) with examples in examples/.

Installation

npm install gte-typescript-sdk
# or when working locally
npm install
npm run build

Quick start

import { GteSdk } from "gte-typescript-sdk";

const sdk = new GteSdk();
const config = sdk.getChainConfig();
const [market] = await sdk.getMarkets({ marketType: "amm", limit: 1 });

const quote = await sdk.getQuote({
  tokenIn: market.baseToken,
  tokenOut: market.quoteToken,
  amountIn: "0.25", // human-readable units
});

const approveTx = await sdk.buildApprove({
  tokenAddress: market.baseToken.address,
});

const { tx: swapTx } = await sdk.buildSwapExactIn({
  tokenIn: market.baseToken,
  tokenOut: market.quoteToken,
  amountIn: "0.25",
  quote,
  recipient: "0xYourWallet",
});

const quoteOut = await sdk.getQuoteExactOut({
  tokenIn: market.baseToken,
  tokenOut: market.quoteToken,
  amountOut: "1",
});

const { tx: swapExactOutTx } = await sdk.buildSwapExactOut({
  tokenIn: market.baseToken,
  tokenOut: market.quoteToken,
  amountOut: "1",
  quote: quoteOut,
  recipient: "0xYourWallet",
  useNativeIn: true, // optional: native ETH in/out supported when path touches WETH
});

const portfolio = await sdk.getUserPortfolio("0xYourWallet");
console.log(portfolio.totalUsdBalance);

Each builder returns the to, data, and value payload ready to hand to wagmi/ethers/viem for signing.

Heads up on CORS: The public MegaETH endpoints do not send permissive CORS headers, so direct browser calls to https://api-testnet.gte.xyz will fail (TypeError: Failed to fetch). Consume this SDK from a Next.js API route/server component, a custom proxy, or any Node backend. Forward the data/transactions to your React UI rather than instantiating GteSdk in the browser.

Native ETH swaps

If you want to send or receive native ETH, pass useNativeIn and/or useNativeOut to buildSwapExactIn and ensure your quote path starts/ends with the wrapped native token (config.wethAddress).

Examples

  • examples/basic.ts – Node script mirroring examples/uniswap_swap.py from the Python SDK.
  • examples/react/App.tsx – React component showing how to fetch markets, render a quote, and preview the approval/swap payloads inside DeOperator-style flows.

Run the Node example after building:

npm run build
node --loader ts-node/esm examples/basic.ts

API surface

| Method | Description | | --- | --- | | getChainConfig() | Returns the MegaETH testnet config + router/WETH addresses. | | getMarkets(params) | Calls /markets using the official OpenAPI spec. | | getTokens(params) / getToken(address) | Fetch token metadata from /tokens and /tokens/{address}. | | getMarket(address) | Fetch a single market. | | getMarketTrades(address, params) | Returns /markets/{market}/trades. | | getMarketOrderBook(address, limit?) | Returns /markets/{market}/book. | | getMarketCandles(address, params) | Returns /markets/{market}/candles. | | getUserPortfolio(address) | Returns balances + USD valuations for a wallet from /users/{address}/portfolio. | | getQuote({ tokenIn, tokenOut, amountIn, slippageBps }) | Reads getAmountsOut from the Uniswap v2 router to provide amount + price. | | getQuoteExactOut({ tokenIn, tokenOut, amountOut, slippageBps }) | Reads getAmountsIn for exact-out pricing. | | buildApprove({ tokenAddress, spender?, amount? }) | Encodes an ERC-20 approval; defaults to max approval for the MegaETH AMM router. | | buildSwapExactIn({ tokenIn, tokenOut, amountIn, recipient, quote?, deadlineSeconds?, useNativeIn?, useNativeOut? }) | Builds the swapExact* transaction matching the Python reference implementation. | | buildSwapExactOut({ tokenIn, tokenOut, amountOut, recipient, quote?, deadlineSeconds?, useNativeIn?, useNativeOut? }) | Builds the exact-output counterparts (swap*ForExact*). |

See src/sdk.ts for more detail; all behavior was ported directly from clients/execution in the Python repo.

Development

npm install
npm run build

The SDK is dependency-light (only viem), fully typed, and ready to publish or consume in a React bundler without extra shims.