@0xtrails/tvm
v0.2.3
Published
Tron (TVM) plugin for the 0xtrails SDK
Readme
@0xtrails/tvm
Tron (TVM) adapter for the Trails SDK. Enables funding from a Tron wallet into any EVM chain via Relay edge payments.
Install
npm install 0xtrails @0xtrails/tvmRequired: polyfill Buffer
This package pulls in TronWeb (via @tronweb3/tronwallet-adapters), which references the Node Buffer global at module-evaluation time. Browsers don't provide it, and modern bundlers (Vite, Rollup, webpack 5+) do not auto-polyfill Node globals. Without a polyfill your app throws Uncaught ReferenceError: Buffer is not defined on load and renders blank.
Install the polyfill and import it before any module that loads @0xtrails/tvm:
npm install buffer// polyfills.ts — must be imported first, before your app entry
import { Buffer } from "buffer"
if (typeof globalThis.Buffer === "undefined") {
globalThis.Buffer = Buffer
}// index.tsx (app entry)
import "./polyfills"
// ...the rest of your appWith Vite you can alternatively use vite-plugin-node-polyfills to provide Buffer globally.
Quick start
import { TrailsWidget, evmAdapter } from '0xtrails'
import { tronAdapter } from '@0xtrails/tvm'
const adapters = [
evmAdapter({ wallets: [{ id: 'injected', name: 'MetaMask' }] }),
// Auto-detect installed Tron wallets (TronLink, etc.).
tronAdapter(),
]
export function App() {
return (
<TrailsWidget
apiKey="YOUR_TRAILS_API_KEY"
adapters={adapters}
fundOptions={{ fundMethodsList: ['connected-wallet'] }}
renderInline
/>
)
}tronAdapter
import { tronAdapter } from '@0xtrails/tvm'
tronAdapter(options?: TronAdapterOptions): TrailsAdapterConfigReturns a TrailsAdapterConfig for use in the adapters prop of TrailsWidget or TrailsProvider. Auto-registers the TVM edge plugin.
Options
| Option | Type | Description |
|--------|------|-------------|
| wallet | TronWalletContextValue \| null | Optional pre-built Tron wallet source. Omit to auto-detect installed Tron wallets. |
| preferredWalletId | string | Optional auto-detected wallet id to prefer. |
| silentReconnect | boolean | Whether to silently reconnect previously trusted wallets. Defaults to true. |
Enabling Tron funding
Tron funding is available through the connected-wallet funding path when tronAdapter is configured:
<TrailsWidget
apiKey={apiKey}
adapters={[tronAdapter()]}
fundOptions={{
fundMethodsList: ['connected-wallet', 'crypto-transfer'],
}}
renderInline
/>Supported origin token: USDT (TRC-20).
Wallet inputs
Usually omit wallet and let the adapter auto-detect installed Tron wallets:
tronAdapter()To bridge a host-managed wallet, pass a TronWalletContextValue:
import { createTronWallet } from '@0xtrails/tvm'
const tronWallet = createTronWallet({
connected,
address, // base58 T-format
signTransaction, // (tx) => Promise<tx>
tronWeb, // TronWeb instance
})
const adapters = [tronAdapter({ wallet: tronWallet })]License
Apache-2.0
