Skip to content

Sponsored gas toggle#10

Merged
PierreBesson merged 6 commits into
mainfrom
sponsored-gas-toggle
May 10, 2026
Merged

Sponsored gas toggle#10
PierreBesson merged 6 commits into
mainfrom
sponsored-gas-toggle

Conversation

@PierreBesson

Copy link
Copy Markdown
Member

No description provided.

PierreBesson and others added 2 commits May 10, 2026 21:33
Adds a "Sponsored gas" switch on the wallet page so the connected user can
turn Chain.Giving's CGPaymaster sponsorship off for their own transactions.
Preference is persisted in localStorage and synced across tabs (storage
event) and within the same tab (custom event).

When off, useOrgGasSponsorship treats isSponsorshipAvailable as false, so
useSponsoredWrite skips wallet_sendCalls + paymasterService and falls back
to writeContractAsync — the wallet pays its own gas. The "Create Program
(Gas Sponsored)" label flips automatically since it reads the same flag.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented May 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
chain-giving-nextjs Ready Ready Preview, Comment May 10, 2026 8:26pm

Reown AppKit's wagmi adapter can surface the chain id in CAIP-2 form
("eip155:84532") on the connector's wallet client. viem later calls
BigInt(chainId) when encoding the tx, which throws SyntaxError. Passing
chainId explicitly to writeContractAsync forces wagmi to resolve the
chain from wagmiConfig instead, sidestepping the adapter's bad value.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
PierreBesson and others added 2 commits May 10, 2026 22:07
Both the initial render state and the post-hydration read now default
to false when no preference is stored, so wallets get plain
writeContract by default and have to opt in to sponsorship.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Reown AppKit's embedded-wallet provider answers eth_chainId with the
CAIP-2 form ("eip155:N"). viem then runs that through hexToNumber →
BigInt(...) and throws SyntaxError, killing any write that hits the
fallback path.

- useSponsoredWrite: drop wagmi's useWriteContract on the non-sponsored
  path and call viem.writeContract directly on a wallet client whose
  transport proxies eth_chainId responses, rewriting "eip155:N" to a
  proper hex chain id. The Chain object is also pinned from wagmiConfig
  instead of trusting the connector's chain.

- useTransactor: tolerate walletClient.getChainId() throwing, since
  the result is only used to build the block-explorer link.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ReturnType<typeof useWalletClient>["data"] was resolving to {} during
the Next.js build, breaking `raw.account`. Typing the parameter as
viem's WalletClient directly is simpler and resolves cleanly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@PierreBesson PierreBesson merged commit 8b54c67 into main May 10, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant