Wallet Integration

This guide outlines the steps for wallet developers to integrate MegaFuel, enabling gas fee sponsorship for their users. The MegaFuel solution is designed as a permissionless system, welcoming integration from all wallet providers without restrictions.

Paymaster Endpoint

📘

Supported on both BNB Smart Chain and OpBNB.

Endpoint

  • BNB Smart Chain (BSC)

    • Mainnet: https://bsc-megafuel.nodereal.io/
    • Testnet: https://bsc-megafuel-testnet.nodereal.io/
  • opBNB

    • Mainnet: https://opbnb-megafuel.nodereal.io/
    • Testnet: https://opbnb-megafuel-testnet.nodereal.io/

Example Client Code

This repository contains a series of code examples demonstrating MegaFuel integration across multiple scenarios, including wallet integration and payment gateway integration. The codebase is implemented in both Golang and JavaScript.

https://github.com/node-real/megafuel-client-example

Interaction Workflow

Integration involves modifying the transaction creation and sending process to interact with MegaFuel paymaster. For detailed information about the paymaster API interface, please refer to this document.

The main steps are:

  1. Transaction Preparation:
    • When a user initiates a transaction, first call pm_sponsorable to check if it's eligible for sponsorship.
    • If sponsorable, set the transaction's gas price to zero.
  2. User Notification:
    • Inform the user that the transaction will be gas-free and sponsored by the "sponsor name" returned by the API.
  3. Transaction Signing:
    • Have the user sign the zero-gas-price transaction.
  4. Submission to Paymaster:
    • Send the signed transaction to the paymaster using eth_sendRawTransaction.
  5. Response Handling:
    • Process the paymaster's response:
      • If successful, inform the user that the transaction is submitted.
      • If failed, consider falling back to normal transaction processing or inform the user of the failure.
  6. Transaction Monitoring:
    • Monitor the transaction status as usual.

Best Practice

  1. Always check sponsorability before setting gas price to zero.
  2. Provide clear information to user about who sponsor the tx.
  3. Implement proper error handling for cases where sponsorship fails.
  4. Consider fallback mechanisms for non-sponsored transactions.