@t402/polkadot
v2.7.1
Published
T402 Polkadot Asset Hub mechanism - USDT payments on Polkadot
Downloads
609
Maintainers
Readme
@t402/polkadot
Polkadot Asset Hub implementation of the t402 payment protocol using the exact-direct payment scheme with Assets Pallet transfers.
Installation
npm install @t402/polkadot
# or
pnpm add @t402/polkadotOverview
This package provides support for USDT payments on Polkadot Asset Hub parachains using the exact-direct scheme. The client executes the transfer directly on-chain, then provides the extrinsic hash as proof of payment.
Three main components:
- Client - For applications that make payments (have Polkadot wallets)
- Facilitator - For payment processors that verify extrinsics via Subscan
- Server - For resource servers that accept payments and build payment requirements
Supported Networks
| Network | CAIP-2 Identifier | Asset ID | Status |
|---------|-------------------|----------|--------|
| Polkadot Asset Hub | polkadot:68d56f15f85d3136970ec16946040bc1 | 1984 | Production |
| Kusama Asset Hub | polkadot:48239ef607d7928... | 1984 | Production |
| Westend Asset Hub | polkadot:e143f23803ac50e8f6f8e62695d1ce9e | 1984 | Testnet |
Package Exports
Main Package (@t402/polkadot)
Constants:
POLKADOT_ASSET_HUB_CAIP2- CAIP-2 identifier for Polkadot Asset HubKUSAMA_ASSET_HUB_CAIP2- CAIP-2 identifier for Kusama Asset HubWESTEND_ASSET_HUB_CAIP2- CAIP-2 identifier for Westend testnetPOLKADOT_NETWORKS- Array of supported networksgetNetworkConfig(network)- Get network configuration
Tokens:
USDT_POLKADOT- USDT token config (Asset ID: 1984)TOKEN_REGISTRY- Token configurations by networkgetTokenConfig(network, symbol)- Get token by symbolgetDefaultToken(network)- Get default token for network
Utilities:
isValidAddress(address)- Validate SS58 address formatisValidExtrinsicHash(hash)- Validate extrinsic hash formatcompareAddresses(addr1, addr2)- Compare two addressesformatAmount(amount, decimals)- Format for displayparseAmount(amount, decimals)- Parse to smallest unitsextractAssetTransfer(extrinsic)- Extract transfer details
Client (@t402/polkadot/exact-direct/client)
import { createExactDirectPolkadotClient } from '@t402/polkadot/exact-direct/client';
const client = createExactDirectPolkadotClient({
signer: myPolkadotSigner,
});Server (@t402/polkadot/exact-direct/server)
import { registerExactDirectPolkadotServer } from '@t402/polkadot/exact-direct/server';
registerExactDirectPolkadotServer(server);Facilitator (@t402/polkadot/exact-direct/facilitator)
import { createExactDirectPolkadotFacilitator } from '@t402/polkadot/exact-direct/facilitator';
const facilitator = createExactDirectPolkadotFacilitator(signer);Payment Flow
- Client requests protected resource
- Server responds with 402 + payment requirements (network, amount, payTo)
- Client executes
assets.transferextrinsic on Polkadot Asset Hub - Client submits extrinsic hash as payment proof
- Facilitator queries Subscan API to verify the extrinsic
- Facilitator confirms payment matches requirements
Payload Structure
interface ExactDirectPolkadotPayload {
extrinsicHash: string; // 0x-prefixed extrinsic hash
blockHash: string; // 0x-prefixed block hash
extrinsicIndex: number; // Index within block
from: string; // Sender SS58 address
to: string; // Recipient SS58 address
amount: string; // Amount in smallest units
assetId: number; // Asset ID (1984 for USDT)
}Address Format
Polkadot uses SS58 addresses:
- 45-50 characters
- Base58 encoded (no 0, O, I, l)
- Network-specific prefixes (0 for Polkadot, 2 for Kusama, 42 for generic)
Examples:
15oF4uVJwmo4TdGW7VfQxNLavjCXviqxT9S1MgbjMNHr6Sp5 (Polkadot)
HNZata7iMYWmk5RvZRTiAsSDhV8366zq2YGb3tLH5Upf74F (Kusama)Development
# Build
pnpm build
# Test
pnpm test
# Test with coverage
pnpm test:coverage
# Lint
pnpm lintRelated Packages
@t402/core- Core protocol types and client@t402/fetch- HTTP wrapper with automatic payment handling@t402/evm- EVM implementation@t402/svm- Solana implementation@t402/ton- TON implementation@t402/tron- TRON implementation@t402/near- NEAR Protocol implementation@t402/aptos- Aptos implementation@t402/tezos- Tezos implementation@t402/stacks- Stacks implementation@t402/cosmos- Cosmos (Noble) implementation
