Create gas sponsored developer wallet set
Create a gas sponsored developer wallet and execute contract function using the wallet
Creating a user gas-sponsored developer wallet set and wallet is nearly identical to creating a standard developer wallet, with minor distinctions. In this article, we'll delve into these distinctions. Wallets generated from a standard wallet set are known as externally owned accounts (EOAs), while wallets created from gas-sponsored wallet sets are contract accounts (following the EIP-4337 standard for smart contract accounts). Both types of wallets possess the capability to sign messages, execute digital asset transfers, and interact with smart contracts. However, for the purpose of this tutorial, we will focus on executing certain smart contract functions, as we have already covered token transfers in the previous article.
Prerequisites
Create a Developer Account and acquire an API key in the Dashboard.
Please note that you can not repeat idempotencyKey
, except the initial transaction failed as it will raise a 401 error.
1. Create Gas Sponsored Wallet Set
To establish a gas-sponsored wallet set, you can initiate a request to POST /wallet-sets/developer/create, similar to the process for creating a standard wallet set. However, there are two additional parameters to consider: isGasSponsored
and sponsorOnlyTransfersToWalletSetAddresses
, both of which are boolean values. By default, isGasSponsored
is set to false
, while sponsorOnlyTransfersToWalletSetAddresses
is set to true
.
To create a gas-sponsored wallet address, you should set isGasSponsored
to true
. Depending on whether you want to sponsor all user transactions, including transfers outside your business ecosystem, you can choose to set sponsorOnlyTransfersToWalletSetAddresses
to false
. On the other hand, if you wish to sponsor only transactions within your ecosystem, which includes digital asset transfers among your business users and contract interactions, you can proceed to set sponsorOnlyTransfersToWalletSetAddresses
to true
.
For the purpose of this tutorial we'll be creating a gas sponsored wallet set to sponsor all users' transactions gas fees.
2. Create Wallet
Creating a wallet within the gas-sponsored wallet set follows the same procedure as for a standard wallet set. The only distinction lies in the Response Body
, where the accountType
will be SMART-ACCOUNT
instead of EOA
for the standard wallet set. Initiate a request to POST /wallets/developer/create, utilising the walletSet.id and walletSetSecretCipherText obtained from step 1, to create a wallet.
3. Lookup business gas sponsor address and balance
Lookup your business gas sponsor wallet address and balance by making a request to GET /wallet-sets/{id}/sponsor/{blockchain}/developer
.
Variables explained as follows:
id
is the wallet set id. Using6519c5d92b8a095cb141ca0f
for this tutorialblockchain
is the preferred blockchain you'd like to fund. Since the created wallet usesETH-SEPOLIA
we'll be using the same blockchain.
4. Top-up sponsor address balance
Acquire Sepolia ETH tokens through the Alchemy Sepolia Faucet and proceed to transfer them to the sponsor wallet address provided in the response body from running the previous step and repeat the previous step to confirm that your balance has been successfully updated, before proceeding.
5. Execute contract transaction
Make a request to POST /transactions/contract-execution/developer
just like in the example below. 0x468BCa19cf28f5b282F1702006481a893Aa2cde8
is the contract address to a Mock USDT token and we want to approve 0x2367BFF998714005b227E8AD3FA425074bee5914
to spend 1000000000000 USDT
from our balance.
When executing a contract function and you're required to send value enter the value in ether instead of wei e.g. 0.1 instead of 100000000000000000
6. Check Transaction State
Make a request to GET /transactions/{id}/developer?walletId={walletId}
to return the specific transaction details using the id from previous step response body.
When the transaction.state
is COMPLETE
, this means that the token has sent from the your wallet to the destination wallet.
You can also check the transaction using the txHash
on Sepolia Etherscan and check that you have given the allowance to the address in the abiParameters
. Inspect the balance of sponsor wallet and compare with the previous balance, the difference is the amount of gas used to execute the transaction.
Last updated