Jan 10, 2025

Gasless MassPay: Send Tokens to Users with Zero Gas Fees

Gasless MassPay: Send Tokens to Users with Zero Gas Fees

Mass payments are one of the most popular ways to distribute tokens. However, most existing mass payment solutions are needlessly complex and consume excessive gas fees.

We've developed a simple mass payment tool using a paymaster that lets you send SBC (Stable Coin) to any recipient by uploading a file or entering wallet details—with all gas fees covered.

MassPay is an open-source project available to developers on GitHub.

Watch the demo

Let’s take a closer look at how to use this.

There are two modes (1) copy and paste and (2) uploading a CSV file.

Copy and paste

If you only have a handful of addresses and the amounts on hand, simply copy and paste each address and their amounts, separated by a comma. For example, the following input sends 0.01 SBC to 0xB5f6fECd59dAd3d5bA4Dfe8FcCA6617CE71B99f9 and 0.001 SBC to 0x589c0e47DE10e0946e2365580B700790AAAbe9f7


Upload a CSV

If you have a large list of users, put the data in a CSV file and simply upload it. You’ll need to prepend a header row address,amount to your data set.

After choosing your preferred input method, you'll see a confirmation dialog that shows:

  • the first and last three addresses and amounts

  • your current SBC balance

  • the total SBC you’ll spend when the mass pay is done, and

  • the remaining SBC balance in your wallet

Confirm and send

First, you'll need to permit your smart account (smart contract wallet) to spend your SBC. Then, sign a message that initiates the mass pay transaction. Once the transaction is complete, you'll receive a blockchain scanner link showing its status and execution details.

Know the tech

One of the major use cases of Account Abstraction (ERC-4337) is the ability to sponsor gas on behalf of users. This is possible through using Paymasters, one of the key components of ERC-4337.

ERC-4337 introduces several key concepts that enable gasless transactions.

A Smart Account is a smart contract wallet that is deployed on-chain and can have one or more owners. Smart accounts are managed by contract accounts and rely on code instead of private keys.

A User Operation is a structured object that describes a transaction to be sent on behalf of a user. User operations must be sent from a Smart Account, is usually sent to a Bundler, and eventually to an EntryPoint.

The EntryPoint is a special singleton contract on each EVM compatible blockchain that validates and executes user operations.

A Bundler is a node that handles User Operations, builds user operations into transactions, and add them to the current block while it’s still valid.

Paymasters are a helper contract that agrees to pay for the transaction on behalf of the sender.

Because of the intricacies and complexity working with Paymasters, a number of solution providers help make it easier:

  • Pimlico

  • Alchemy

  • Biconomy

  • … and more

We selected Pimlico for developing the MassPay solution because it offers a developer-friendly SDK and straightforward implementation process.

Let's take a look at the code together. You can find it on GitHub here.

Create a smart account

First, you need to create a smart account owned by the user's wallet. You can do this using the toSimpleSmartAccount converter function.

Create a smart account client

Next, we create a Smart Account Client — a wrapper object that handles all the functions needed for working with user operations.

pimlicoClient is the RPC endpoint from Pimlico that enables both bundler and paymaster functionality.

Build the user operation

Then, we want to build the mass pay functionality into a user operation. Technically, this translates to:

  1. Asking the user to sign a permit to allow the smart account (sender) to “spend” the total amount of ERC20 token (SBC) from the user’s wallet

  2. Calling the ERC20’s transferFrom function to transfer each designated amount of SBC from the smart account to each destination address

We use encodeFunctionData from viem to package an array of instructions like this.

const calls = [
	// 1. Ask user to sign permit
	{ 
		from: "0x...", // owner address
		to: "0x...", // address
		data: "0x..................", // calldata for permit
	},
	// 2. Call transferFrom to make each transfer
	{ 
		from: "0x...", // owner address
		to: "0x...", // address
		data: "0x..................", // calldata for transfer 1
	},
	// ...
	// ... the last (N-th) address
	{ 
		from: "0x...", // owner address
		to: "0x...", // address
		data: "0x..................", // calldata for transfer N
	}
]

Finally, we call sendTransaction from our created smartAccountClient and receive a hash, which we can then look up in Base’s blockchain scanner.

And that’s how easy it is to airdrop to multiple users without paying any gas.

See the code

The code for MassPay is available in Github here.

Next steps

If you have thoughts, improvements, or would like to contribute to the project, please let us know in Telegram.


Join the SBC

ecosystem

Partner with us to build a global, free, and accessible payment network.

Join the SBC

ecosystem

Partner with us to build a global, free, and accessible payment network.

Join the SBC

ecosystem

Partner with us to build a global, free, and accessible payment network.

Join the SBC

ecosystem

Partner with us to build a global, free, and accessible payment network.