expand.network
  • Overview
  • Getting Started
  • 🔑How do I get my API Key?
  • 📑List of All Endpoints
  • ⚙️SDK
    • Overview
    • Getting Started
  • ⛓️INTEGRATIONS
    • ⚡Blockchains
      • EVM based blockchains
        • Ethereum
        • Binance Smart Chain
        • Avalanche - C
        • Avalanche - P
        • Avalanche - X
        • Polygon
        • Cronos
        • Arbitrum
        • Fantom
        • Optimism
        • Base
        • zkSync Era
        • Mantle
      • Non-EVM based chains
        • Tron
        • Solana
        • Near
        • Algorand
        • Aptos
        • Sui
        • Starknet
        • TON
        • Cosmos Hub
        • Osmosis
        • Stacks
        • Bitcoin
        • Stellar
          • Stellar RWA
        • XRP Ledger
          • XRP Ledger RWA
    • ⚡Bridges
      • Stargate
      • Stargate V2
      • Squid Router
      • Squid Router V2
      • Allbridge Classic
      • Allbridge Core
    • ⚡DEX & DEX Aggregators
      • Uniswap V2
      • Uniswap V3
      • Uniswap X
      • Sushiswap V2
      • PancakeSwap V2
      • PancakeSwap V3
      • Aerodrome
      • Camelot V3
      • Curve V2
      • Balancer V2
      • STON.fi
      • Trader Joe
      • Orca
      • Raydium
      • SDEX
      • Cetus
      • REF Finance
      • Liquidswap
      • Sologenic
      • Alex
      • 0x (Aggregator)
      • 1inch (Aggregator)
      • Kyberswap (Aggregator)
        • Kyberswap ( Limit Order Endpoints )
      • Jupiter (Aggregator)
    • ⚡Derivatives
      • dYdX V4
    • ⚡Fungible Tokens
      • ERC20
      • WETH
    • ⚡Lending Protocols
      • Aave V2
      • Aave V3
      • Compound V2
      • Compound V3
      • Morpho
    • ⚡Yield Aggregators
      • Yearn Finance V2
      • Harvest Finance
      • Pendle
    • ⚡Liquid Staking
      • Chorus One
      • Lido V2
      • Stader
      • Benqi
      • Jito
      • EigenLayer
    • ⚡Non Fungible Tokens
      • ERC721
      • ERC1155
      • Metaplex
    • ⚡Oracles
      • ChainLink
      • WinkLink
      • Pyth Network
      • RedStone
    • ⚡Stablecoins
      • EVM
    • ⚡Synthetics
      • Synthetix
    • ⚡Supported Wallets
      • MPC Wallets
        • DFNS
        • FORDEFI
        • FIREBLOCKS
        • CIRCLE
      • HD Wallets
        • PHANTOM
        • COINBASE
        • TON Wallet
      • Wallet Connect v2
  • How To
    • Execute a Local Swap
    • Execute a Cross Chain Swap
    • Use Limit Orders
    • Lend and Borrow
    • Provision Liquidity
      • Adding Liquidity
      • Removing liquidity
    • Yield Farm
    • Use Our Transaction Decoder
    • Submit an RFQ
    • Subscribe to Events
    • Stream Data (WebSocket)
      • Stream Transaction
      • Stream Trade
      • Stream Gas
      • Stream Ticker Price
    • Source Pricing
    • Track Memecoins
    • Manage Token Approvals
  • Use Cases
    • Trade Reconciliation
    • Portfolio Management
    • Trading Features
    • On-Chain Data: DEX Liquidity Pool Forensics
    • Transaction and Pool Analysis
  • Account Abstraction
    • Overview
      • User Endpoints
      • Paymaster Endpoint
      • Bundler Endpoint
    • ⚙️SDK - Overview
  • Additional Info
    • Error Messages
    • Client-Side Security Essentials
    • Compute Unit Costs
    • API Metadata
    • Audit Certificate
    • Brand Assets
    • FAQs
    • Quicknode Marketplace
      • DEX
      • Lending Protocols
  • ID's
    • Chain IDs
    • Bridge IDs
      • Internal Chain IDs for Bridges
    • DEX IDs
    • Lending Protocol IDs
    • Yield Aggregator ID
    • Liquid Staking IDs
    • Oracle IDs
    • Stablecoin IDs
    • Derivatives IDs
    • Synthetics IDs
  • Mapping
    • Blockchains
    • DEXs
      • Uniswap V2
      • Uniswap V3
      • Sushiswap
      • PancakeSwap
      • Curve
      • Balancer
    • Lending Protocols
      • Aave
      • Compound
  • Protocol Spender
    • Spender list
Powered by GitBook
On this page
  • Response Schema:
  • Streaming transactions:
  • Expected Output:
  • How to disconnect:
  1. How To
  2. Stream Data (WebSocket)

Stream Transaction

Stream transactions will help you to track the activity of the subscribed address on the blockchain.(Currently Available for Ethereum Only)

Response Schema:

Field
Description

blockHash

Hash of the block.

blockNumber

Number of the block.

chainId

0x1 denotes ethereum.

from

Ethereum address of the sender of the transaction.

gas

Gas provided by the sender.

gasPrice

Amount of Ether that the sender is willing to pay for each unit of gas.

maxPriorityFeePerGas

max Priority Fee Per Gas of transaction

maxFeePerGas

max Fee Per Gas of transaction

accessList

accessList of transaction

hash

Hash of the transaction.

input

The data sent along with the transaction.

nonce

Unique value that is incremented with each transaction and is unique to each account.

v,r,s

Signature values that are used to verify the transaction's authenticity.

to

Ethereum address of the recipient of the transaction.

transactionIndex

Integer of the transactions index position in the block.

value

Amount of Ether to be transferred in the transaction.

yParity

yParity of transactions

timestamp

Block timestamp

type

Type of transaction method

tokenStandard

Token Standard involved in the transaction. Like ERC20, ERC721 and ERC1155

Streaming transactions:

Users can stream transactions in two ways:

Example 1: via wscat script (For Linux based distro)

First, the user needs to run the following command in their terminal to install wscat in their system:

npm install -g wscat 

After installing wscat, the user needs to create a shell script and paste the following sample code:

Client Side Sample Socket Code :

#!/bin/bash

echo "Price Discovery\n"
read -p "x-api-key: " YOUR_API_KEY
wscat -c wss://pricediscovery.expand.network -H authorization:secret-token -H x-api-key:$YOUR_API_KEY

Once the file has been saved, the user will need to grant permission for it to be executed. This can be accomplished by executing the following command:

chmod +x YOUR_FILE_NAME.sh

After following the above steps, the user needs to run the file. This can be done by entering the filename in the console.

Executing a query:

After executing the aforementioned file(shell script), the user will be prompted to input the appropriate API key.

After entering the API key, user can subscribe to following actions:

{"action": "streamTransactions"}

Make sure you are connected to the WebSocket before you perform the following queries.

Applying a filter in the query:

Users can apply the following filters in their query:-

  • addresses

  • minAmount(Wei)

  • maxAmount(Wei)

The above filters can be applied in any combination, using the following syntax:

{"action": "streamTransactions", "addresses": "array_of_strings", "minAmount": "minimum_amount_in_wei", "maxAmount": "maximum_amount_in_wei"}

Sample Query:

{"action": "streamTransactions", "addresses": ["0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D","0xdafea492d9c6733ae3d56b7ed1adb60692c98bc5"], "minAmount": "0", "maxAmount": "1000000000000000000000000000000000000"}

Example 2. via javascript code

First, the user needs to run the following command in their terminal to install wscat in their system:

npm i ws

After installing ws, the user needs to run the following sample code on their device to start streaming:

Client Side Sample Socket Code :

const WebSocket = require('ws');
const url = 'wss://pricediscovery.expand.network';
const options = {
  headers: {
    Authorization: 'secret-token',
    'x-api-key': 'YOUR_API_KEY', // Replace this with your API Key
  }
};

const ws = new WebSocket(url, options);

ws.on('open', () => {
  console.log('WebSocket connection established.');
  const payload = {
    action: "streamTransactions",
    addresses: ["0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D","0xdafea492d9c6733ae3d56b7ed1adb60692c98bc5"],
    minAmount: "0",
    maxAmount: "10000000000000000000000000000000000000000000"
  };
  ws.send(JSON.stringify(payload));
});


ws.on('message', (data) => {
  console.log(`Received data: ${data}`);
});

ws.on('close', () => {
  console.log('WebSocket connection closed.');
});

The payload can be modified, depending on the action.

Expected Output:

{
    "blockHash": "0x98aaecde2e4f18d962bd928b3f438ceb68b7f2e167b05d457bdad4588b0945fb",
    "blockNumber": 21921404,
    "from": "0x891022873dd8e82d4817cc3cd6f8850dfcf0d50f",
    "gas": 203518,
    "gasPrice": "762473304",
    "maxPriorityFeePerGas": "100000000",
    "maxFeePerGas": "781194160",
    "hash": "0x8466921039f757c5258afc197ca6def50f09d34cc3ba2d75a3f78d920b5ec1c4",
    "input": "0x095ea7b30000000000000000000000000016ab524fdf4e8289d4066ad6deef8226c637ca000000000000000000000000000000000000000000000000000000004abe8580",
    "nonce": 1,
    "to": "0x226bb599a12c826476e3a771454697ea52e9e220",
    "transactionIndex": 137,
    "value": "0",
    "type": "approve",
    "accessList": [],
    "chainId": "0x1",
    "v": "0x1",
    "yParity": "0x1",
    "r": "0x3687ccbc146c727b1eaa93c1c445c40b6d6d25be00fb1e65a139ba30235035d8",
    "s": "0x30af56312a1e31f40156aa50a170ea5cc7e3b4a48a84a58c57091c56eed6f717",
    "tokenStandard": [
        "ERC-20"
    ],
    "timestamp": 1740463115
}

How to disconnect:

To disconnect from our API, enter ctrl-c in the connected console.

PreviousStream Data (WebSocket)NextStream Trade

Last updated 2 months ago