Multis and the Gas Station Network
Today, in order to use their Multis’ account (send a transaction, change account parameters on the blockchain, etc.), users must pay a network fee called gas, payable only in ETH. Given the nature of Multis’s multisignature smart contracts (an account is managed by a team), account owners need to have enough funds in their personal wallets in order to use their shared Multis account.
You can already see the pain: companies need to either fund their owners personal accounts as needed, to cover for network fees in anticipation, or owners can keep track of their personal expenses and frequently submit refund requests. This causes a lot of confusion, but also a lot of friction when it comes to UX.
This post is an overview of the work Multis has been doing to tackle this challenge.
Enter the Gas Station Network (GSN)
The Gas Station Network is an effort lead by OpenZeppelin, Tabookey and Portis to solve this problem, by allowing users of a smart contract to send transactions without needing to pay for gas themselves. Sounds like magic? Let’s dive in.
GSN in a nutshell
Signing Ethereum transactions is free, broadcasting them to the blockchain on the other hand is what costs gas. In a GSN configuration, owners only sign transactions and then request that they be broadcasted by a relayer. This relayer is going to be the one effectively broadcasting the signed transaction and paying for the gas.
In order for the relay to pay for gas on behalf of users, companies need to deposit funds for the relay to use. When funds run out for a specific company, owners will be invited to pay gas fees as usual, abstracting away the GSN machinery. Furthermore, the process of funding the relay and paying for gas fees happens autonomously by the use of smart contracts, effectively removing the need for a trusted third party.
The network is orchestrated by a single smart contract instance called the RelayHub, which keeps track of off-chain relayers, handles relayed transactions, and ensures all parties are honest, removing the need to trust any single relayer.
Relayers are thus part of a trustless P2P network, where anyone can participate by running a relayer (and earn money by charging contracts for pushing transactions into the Ethereum blockchain).
Upgrading smart contracts
In order to participate in the Gas Station Network, a smart contract needs to be GSN-capable, that is, to implement a function responsible for receiving relayed calls (discussed later), but under the hood, Multis uses the Gnosis Multisig smart contracts, which were written before GSN and thus are not GSN-capable. Multis is forking Gnosis to implement GSN-capable multisignature smart contracts.
Extending Gnosis Multisigs
- Allow for free account creation: today, opening a Multis account means deploying an instance of the Gnosis Multisig, the gas fees for such an operation need to be paid by the user deploying the contract. By making the Gnosis factory GSN-capable, Multis is going to be capable to offer its users free account creation, by paying gas on their behalf.
- Once an account created through Multis, allow companies to pay for gas on behalf of their own users. This means forking the actual deployable multisignature Gnosis smart contract and making it a valid GSN Recipient.
For this work, Multis is using OpenZeppelin SDKs.
Accepting relayed calls via GSN
In order to be a valid GSN Recipient, a smart contract needs to implement a function called
acceptRelayedCall. This function’s responsibility is to instruct the relay hub to either go ahead and execute a transaction or to reject it. Payment strategies, if any (eg. who gets free gas and who doesn’t), need to be implemented here.
There are multiple payment strategies, that is, to accept or reject a relayed call via the Gas Station Network (GSN), you can, for example, have a white list of trusted users, only allow relayed calls for a subset of functions or even delegate your logic off-chain.
What got our attention however was the possibility to charge users in tokens (issued by Multis, as we will discuss later), automatically getting free gas simply by holding them.
It’s also important to note that relayed call requests can be rejected at no cost to the recipient.
Writing GSN-capable smart contracts
As discussed earlier, there are two aspects to a Multis account, first its creation, technically deploying your own instance of the multisignature smart contract and second, its usage, which happens out of your own self-custodian instance managed only by owners you included in the creation step, or added to your account later on.
Let’s discuss how gasless transactions happen at each of these levels.
Account creation happens through the Multisig Factory managed by Multis. Paying gas fees on behalf of users for the creation phase means funding the Factory by depositing ETH to the GSN Relay hub. This way, anyone trying to create an account throught Multis will not have to pay for gas.
Protection from spam
Since Multis is going to be paying for account creation gas, we needed a way to protect ourselves from a malicious attacker draining the factory funds by creating multiple accounts.
This is where we want to introduce the CryptoDreamers Token.
The CryptoDreamers Token (CDT) is a token issued by Multis, simply holding it allows you to pay for gas in the process of creating a Multis account, with a 1:1 ratio to ETH.
CDT is deployed at the following addresses:
- mainnet - 0x1c4d5ca50419f94fc952a20dddcdc4182ef77cdf
- rinkeby - 0xfabeb0a74538575ce58de2d54ddef4fe2cec4698
Technically, CDT is an implementation of the GSNRecipientERC20Fee interface, this is a rather complex payment strategy, but since it comes built-in with OpenZeppelin SDKs, integrating it was straight forward, since it boils down to extending your contract with both a GSNRecipientERC20Fee and a MinterRole so you can issue tokens.
All you have to do next is implement your minting strategies, and most importantly, only accept relayed calls for users holding your token. Below is how Multis is doing it.
It’s important to note that CDT is to be seen as a kind of a reward, or fidelity points, it has no “coin” ambitions outside of allowing us to offer free gas to select users.
It’s also worth noting that the process is going to be transparent for the user: Multis is going to automatically check if a user holds CDT and offer free account creation accordingly, without any action required from users.
Paying gas fees on behalf of users for daily account usage is different, it’s not a one time operation like account creation, and since Multis accounts are self-custody, we can’t operate a CDT fee mechanism. The only way to offer free gas for this scenario is through directly funding accounts, or what we like to call it: top-ups.
As of writing, Multis has decided to pay for gas fees for all accounts (create yours now to take advantage of this offer)
Now, let’s talk architecture
Being part of the Gas Station Network means providing a whole new infrastructure for how your accounts work, from relaying calls to how you automate account funding, so let’s get a glimpse of what Multis has achieved.
Once you have a Multis GSN-capable account, we made it super easy for you to take advantage of gasless transactions: a simple top-up button.
By using the top-up button, Multis will deposit funds for you at the relay hub, and all your owners will get instant free gas for all transactions, without any more actions or coordination from your side.
Under the hood, Multis is using a serverless architecture to dispatch requests and do the funding. You can read more about our serverless architecture here.
Web3 on nodejs
In order to fund accounts, we need to call the GSN RelayHub’s smart contract
depositFor method, this happens every time a user calls our topup HTTP endpoint, which in turn triggers a cloud function that handles topup requests.
Unlike web DApps where your web3 instance is associated with an Ethereum account (that you get from MetaMask or Portis, or any other wallet the user happens to be using), when a topup request is accepted (after a fair-use check), our web3 instance is being created on a nodejs serverless setting, so we have no account associated with our web3 instance.
We start by encoding transaction data related to the smart contract method call, that we use to construct a transaction object. We then sign it using our account’s private key (an Ethereum account dedicated to topups).
Finally, we broadcast the signed transaction’s raw representation. The gas fees in this case are going to be paid by the account which private key was used to sign the transaction.
- Multis sponsors the creation of MULTISigs: request access here to enjoy a free and frictionless deployment of your MULTISig smart contract.
- Once deployed, Multis allows companies to pay for gas fees on behalf of their users, with a click of a button, so users can enjoy a gasless experience. Multis is currently covering this cost as well on the basis of a fair-use, limited time offer. We call these fee credits.
- You should open an account.