Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions apps/docs/pages/sdk/guides/sponsoring.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,19 @@ import { GuideDemoContainer } from '../../../components/GuideDemoContainer'

# Fee Sponsoring

This guide will demonstrate how you can leverage Fee Sponsoring in your Application to cover
fees for your users.
A Porto Merchant (Sponsor) Account lets your app pay gas on behalf of users.
It is an admin-controlled account that, via your Merchant RPC server,
designates itself as the fee payer and signs fee payments for user calls.
This flow allows you to sponsor or subsidize any transaction fee.

## Usage

- Expose a Merchant RPC endpoint that inspects requests and attaches fee sponsorship
- (Optional) If your server is remote, pass `merchantRpcUrl` to `Porto.create()`
- You can add conditional rules with the `sponsor` option to control when fees are covered

The guide below will show you how to set up a Merchant RPC server and how to use it with Porto
using a Cloudflare Worker, but you can also use any other server framework (Next.js, Deno, Express, etc).

## Template

Expand Down Expand Up @@ -49,9 +60,7 @@ MERCHANT_PRIVATE_KEY=0x...
### Set up Merchant RPC Server

Next, we will set up our Merchant RPC Server at the `/rpc` endpoint of our app.
For this example, we will use a Cloudflare Worker, however, you could also use a
server framework of your choice (Next.js, Deno, Express, etc).
See the [`MerchantRpc` API reference](/sdk/api/merchantRpc/requestHandler).
See the [`MerchantRpc`](/sdk/api/merchantRpc/requestHandler) API reference for more details.

```ts
import { env } from 'cloudflare:workers'
Expand Down Expand Up @@ -86,7 +95,7 @@ const porto = await Porto.create({

### Done

That's it! Once you have a server set up at the `/rpc` path of your app (or another remote URL), Porto will automatically
detect it and route through this endpoint for future calls to perform (and sponsor) a transaction.
That's it! Once you have a server set up at the `/rpc` path of your app (or another remote URL),
Porto will route through this endpoint for future calls to perform (and sponsor) a transaction.

::::