Skip to content

Fee Sponsoring

This guide will demonstrate how you can leverage Fee Sponsoring in your Application to cover fees for your users.

Template

We will base this guide off the following template:

pnpx gitpick ithacaxyz/porto/tree/main/examples/sponsoring-vite

Steps

Connect Account

Follow the Onboard & Discover Accounts guide to get this set up.

Set up Merchant Account

Run the following command to onboard a new Porto Merchant (Sponsor) Account.

pnpx porto onboard -a

Place the address and private key of the merchant account into the .dev.vars file.

MERCHANT_ADDRESS=0x...
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.

import { env } from 'cloudflare:workers'
import { MerchantRpc } from 'porto/server'
 
export default {
  fetch: MerchantRpc.requestHandler({
    address: env.MERCHANT_ADDRESS,
    base: '/rpc',
    key: env.MERCHANT_PRIVATE_KEY,
    // Optionally handle which requests should be sponsored.
    // sponsor(request) {
    //   return true
    // },
  }),
} satisfies ExportedHandler<Env>

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.