Hello everyone,
I am Pilou from Sekai. We are currently building a collectible card game on StarkNet where users could purchase boosters of cards and open them.
Our main problematic is that we would like to cover the gas fees for the users when they open a booster. As they own the asset (aka the booster) on-chain, they are the ones who need to call the booster contract from their account. The signature on the opening transaction must be computed using the user’s signer.
To tackle this, we designed a protocol in which users sign their transactions including the payer (address of the account that will pay for the transaction) in the signed calldata.
The user’s transaction also takes the nonce from the payer account as it will be the one bumped by the execution.
The sponsored transactions are then sent to the classic execute endpoint of the payer account contract (classic OZ Account implementation here). The payer forwards it to the executePaid endpoint of the user account contract (PayableAccount implementation).
This endpoint recomputes the transaction hash of the original user transaction and checks it against the provided user’s signature.
This flow is illustrated in the attached diagram.
Here is an example of such a sponsored transaction : Starkscan - Starknet Block Explorer
I put together a repository to open-source the protocol and get feedback from the StarkNet community : GitHub - sekai-studio/paymaster: Model Account Contract to leverage paymaster protocol
For now, it’s written in “already old” Cairo and tested in Python as I needed to experiment quickly (and not learn a new language). It will be migrated to Cairo 1.0 once the language is stable and the protocol reviewed.
The Cairo part of the repo consists of the PayableAccount implementation.
The Python part offers a library to generate/sign/invoke sponsored transactions in a easy way.
I will also add some more test cases in the next weeks but wanted to have some feedback about this protocol first.
Happy to discuss with you all
Thanks,
Pilou
N.B. : do not pay attention about the data used in the example transaction, we are just big Naruto fans, there’s nothing official !