In this article, we will explore how to seamlessly integrate Trust Wallet’s Smart Accounts with the permissionless.js framework, a library managed by Pimlico to deploy and manage Smart Accounts based on the ERC-4337 standard. Using our SDK, you can create Trust Smart Accounts for your users and enhance your dApp with features such as gasless and batched transactions and much more.
Benefits of a Trust Smart Account
Batch transactions
Sponsored Transactions via Paymaster
Passkey support
Prerequisites
Before you begin, ensure you have the following prerequisites:
Node.js and npm installed on your development environment.
Combine the components in your main App component.
import { useEffect, useState } from"react";import { useAccount, useConnect } from"wagmi";import { Hash } from"viem";import Card from"./components/Card";import SignerConnect from"./components/SignerConnect";import SmartAccountCreate from"./components/SmartAccountCreate";import NFTMint from"./components/NFTMint";import Logo from"./assets/logo.svg";constApp:React.FC= () => {const { connectors,connect } =useConnect();const { address } =useAccount();const [smartAccount,setSmartAccount] =useState<any>();const [step,setStep] =useState<number>(0);const [mintTx,setMintTx] =useState<Hash|undefined>();useEffect(() => {setStep(smartAccount ?2: address ?1:0); }, [address, smartAccount]);useEffect(() => {if (mintTx) {setStep(3); } }, [mintTx]);return ( <divclassName="p-12"> <divclassName="max-w-md mx-auto items-center flex"> <ahref="#"className="mx-auto"> <imgsrc={Logo} alt="Trust Wallet"className="inline-block w-48" /> </a> </div> <divclassName="mt-8 space-y-4 shadow-lg rounded-lg overflow-hidden max-w-md mx-auto bg-white"> <divclassName="p-8 flex flex-col justify-center items-center"> <h1className="mt-4 text-2xl font-semibold text-center"> Trust Smart Account Demo </h1> <pclassName="mt-2 text-gray-600 text-center"> Follow these steps to mint a free gasless NFT leveraging the power of Trust Smart Accounts </p> </div> <Cardstep={step}index={1}title="Connect your wallet"description={address ?`Signer ${address} is connected!`:""} /> {step ===0&& ( <SignerConnectconnectors={connectors} connect={connect} /> )} <Cardstep={step}index={2}title="Create or retrieve your Smart account"description={ smartAccount?`Your Trust Smart Account ${smartAccount.account.address} is Ready!`:"" } /> {step ===1&& ( <SmartAccountCreatesmartAccount={smartAccount}setSmartAccount={setSmartAccount} /> )} <Cardstep={step}index={3}title="Mint NFT"description="NFT is Gasless" /> {step ===2&& ( <NFTMintsmartAccount={smartAccount} setMintTx={setMintTx} /> )} {mintTx && ( <divclassName="p-8 text-center"> <ahref={`https://sepolia.etherscan.io/tx/${mintTx}`}target="_blank"rel="noopener noreferrer"className="text-blue-600 hover:underline text-center" > Your NFT was successfully Minted without any gas fees. Follow the Tx here. </a> </div> )} </div> </div> );};exportdefault App;
Conclusion
By following this guide, you have successfully integrated Trust Smart Accounts into your project and enabled the creation of gasless NFTs. This setup leverages the power of account abstraction, giving a better experience to your users in order to interact with your dApps.
Frequently Asked Questions (FAQs)
Which networks are supported?
Ethereum
Arbitrum
Optimism
BNB
Polygon
Avalanche
opBNB
Base
Testnets:
Sepolia
Are there any costs associated to using Smart Accounts?
No. Only costs are related to paymaster.
Security Information
Audits: Our smart contracts have undergone thorough audits by high-profile security firms, ensuring robust protection against vulnerabilities.
Open Source: Barz, our smart contract wallet solution, is open-sourced, promoting transparency and allowing the community to review and contribute to its development. https://trustwallet.com/blog/introducing-barz-smart-contract-wallet-solution
Passkeys Support: Trust Smart Accounts support passkeys for an additional layer of security, providing a more secure and user-friendly authentication mechanism.
On-chain security monitoring service: All Trust Wallet smart accounts are automatically monitored by our security monitoring infrastructure for free. All users will be able to maintain a highly secure state and could get immediately notified when a hack occurs. For detailed explanation, please reference this doc.