diff --git a/sdk/adapters/overview.mdx b/sdk/adapters/overview.mdx index f6f93da..926b56e 100644 --- a/sdk/adapters/overview.mdx +++ b/sdk/adapters/overview.mdx @@ -15,6 +15,7 @@ Omit adapters entirely and Trails uses its **built-in EVM wallet runtime**, your | [`wagmiAdapter`](/sdk/adapters/wagmi) | `@0xtrails/adapter-wagmi` | Your app uses wagmi (v2 or v3), or a wagmi-based stack such as [Dynamic](/sdk/adapters/dynamic), Privy, or Sequence Connect | | [`evmAdapter`](/sdk/adapters/eip-1193) | `0xtrails` (built in) | You have a raw EIP-1193 provider — `window.ethereum`, an embedded wallet, or any SDK that can expose one | | [`svmAdapter`](/sdk/adapters/solana) | `@0xtrails/svm` | You want to accept or send payments from Solana wallets | +| `tronAdapter` | `@0xtrails/tvm` | You want to accept or send payments from Tron wallets. Requires a [`Buffer` polyfill](#buffer-polyfill-for-tron) | Wallet SDKs that can produce an EIP-1193 provider don't need a dedicated adapter — they plug into `evmAdapter` directly. See the [thirdweb](/sdk/adapters/thirdweb) guide for a complete example of this pattern. @@ -46,9 +47,42 @@ const adapters = [ ] ``` +## Buffer polyfill for Tron + +`tronAdapter` pulls in TronWeb, which reads the Node `Buffer` global while its modules evaluate. Browsers don't define `Buffer`, so without a polyfill the import throws `ReferenceError: Buffer is not defined` and takes down the surrounding React tree — typically a blank page rather than a caught error. + +Install the `buffer` package and assign the global before anything imports the adapter: + +```bash +pnpm add buffer +``` + +```ts +// polyfills.ts +import { Buffer } from 'buffer' + +if (typeof globalThis.Buffer === 'undefined') { + globalThis.Buffer = Buffer +} +``` + +Import it as the first import of the entry that loads `tronAdapter`: + +```tsx +import './polyfills' + +import { Pay } from '0xtrails' +import { tronAdapter } from '@0xtrails/tvm' +``` + +Import order matters — the assignment has to run before TronWeb's modules evaluate, so keep it above the adapter import. Bundlers that hoist or split entries can reorder this; if the error persists, inject the global at build time instead (for example Vite's `define`, or `webpack.ProvidePlugin`). + +`svmAdapter` does not need this — Solana support runs in the browser without a `Buffer` global. + ## Choosing an adapter 1. **No existing wallet stack?** Pass no adapters — the built-in runtime handles injected wallets and WalletConnect. 2. **App on wagmi?** Use [`wagmiAdapter`](/sdk/adapters/wagmi). One package supports wagmi 2 and wagmi 3. Wagmi-based wallet SDKs such as [Dynamic](/sdk/adapters/dynamic) (Fireblocks embedded wallets) plug in the same way — no custom Trails code needed. 3. **Embedded or custom wallet that speaks EIP-1193?** Use [`evmAdapter`](/sdk/adapters/eip-1193). This covers wallet SDKs that expose an EIP-1193 provider directly, such as [thirdweb](/sdk/adapters/thirdweb). 4. **Solana?** Add [`svmAdapter`](/sdk/adapters/solana). +5. **Tron?** Add `tronAdapter`, plus the [`Buffer` polyfill](#buffer-polyfill-for-tron).