General overview
When Relayers execute transactions on behalf of users, they do so via a multicall contract (to be specific, we use Vectorized’s gas-optimized Multicaller contract). This protects the Relayer from malicious transactions. One exception is simple bridge transactions, where thedata
is empty. For these, the Relayer will execute them directly to avoid the gas overhead of using Multicaller.
Sender Attribution
Because transactions are executed via the Relayer / Multicaller, you can’t rely onmsg.sender
for authentication. There are a couple of ways around this:
Unauthenticated Delegation
The simplest solution is if your contract allows one user to take an action on behalf of another user. This works great for actions that don’t require authentication, because they are purely net beneficial to the user:- buying an NFT
- depositing into a vault
- placing an auction bid
- selling the NFT
- withdrawing from the vault
- canceling the bid, etc.
msg.sender
, you could mint via a router contract then have it forwarded the NFT to the user.
Authenticated Delegation
For authenticated actions, you can do those by passing in proof that the user authenticated the action. Currently, you need to build custom signature authentication into your contract, however, in the near future we will be adding support for more standardized flows, such as:- Selling tokens with permit signatures
- MulticallerWithSigner
- ERC2771 Trusted Forwarder
Just-In-Time Gas
Alternatively, you can simply bridge a small amount of gas and have the user execute the transaction themselves. This is viable because of how fast and cheap Relay is, and is backwards compatible with any contract. We will soon add functionality to our SDK to handle this flow completely automatically, but until then, you can do it manually like this:- Estimate the cost of the transaction on destination
- Get a quote to bridge enough gas (small buffer recommended to handle fluctuation)
- User executes the bridge of gas money from Origin to Destination
- User executes the action on Destination
- (Optional) If selling an asset, User could potentially bridge the proceeds back to Origin