Learn everything about Circle and USDC
Section Summary
Section Review: Implementing Gas Station and Smart Contract Accounts
Welcome to this section review! In this chapter, you implemented the Gas Station feature using Smart Contract Accounts (SCAs) in your User-Controlled Wallets project. This summary recaps the steps, changes, and best practices you applied.
Key Update: Switching to Smart Contract Accounts
You began by modifying the existing User-Controlled Wallets project. The only code change required was in the API configuration—specifically within initializeUser in routes.js.
By default, accounts are created as Externally Owned Accounts (EOAs) unless otherwise specified. To use Smart Contract Accounts, you needed to include the account type parameter as "SCA".
Process Recap: Creating a New Smart Contract Wallet
Once you made that change:
- You ran the project using npm run dev.
- You accessed the front-end and created a new user.
- You collected the required credentials:
- App ID (remains the same)
- User ID
- User Token
- Encryption Key
- Challenge ID
You stored these in your .env file just like the first time you created a wallet.
Setting Up the Wallet
After collecting the credentials:
- You returned to the UI and filled out the wallet setup form.
- You entered your App ID, User Token, Encryption Key, and Challenge ID.
- Upon verifying the challenge, you completed PIN setup and recovery questions—finalizing the wallet creation.
In Circle's Dashboard, you could then view the user profile showing:
- Account Type: Smart Contract Account (SCA)
- Status: PIN and Security Questions enabled
Checking Wallet Status and Balance
Once the wallet was initialized:
- You used the command npm run check-wallet-status to confirm the wallet’s live state and retrieve the Wallet ID and address.
- You then checked the balance with npm run check-wallet-balance, confirming that the USDC was available and the native token (MATIC) balance was zero.
Initiating and Verifying Transactions
Next, you initiated a transaction with npm run initiate-transaction. This returned:
- User Token
- Encryption Key
- Challenge ID
You then entered this data into the front-end and verified the challenge once more—not to create the wallet this time, but to authorize the transaction. Since it’s a User-Controlled Wallet, all actions must be confirmed by the user.
Developer vs. User Roles in Verification
As the developer:
- You prepare the Challenge ID and present it to the user.
- The user is responsible for verifying the challenge by entering their PIN and answering recovery questions.
Only after this user confirmation can any blockchain operation—like wallet creation or token transfer—be finalized.
Testnet vs. Mainnet Configuration
- On the testnet, no additional configuration is needed for the Gas Station to work with Smart Contract Accounts.
- On mainnet, additional setup is required. Refer to the official Circle documentation for those production steps.
What You’ve Learned
By this point in the course, you've mastered how to:
- Create both EOAs and SCAs
- Transfer tokens using user-controlled wallets
- Sponsor user gas fees with the Gas Station
- Secure operations using challenge-response verification
Comments
You need to enroll in the course to be able to comment!