In this article, we will explore how to seamlessly integrate with the framework, a library managed by to deploy and manage Smart Accounts based on the ERC-4337 standard. Using our , 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.
An active account with Pimlico for API access.
Create your Pimlico account
Get Started
Simplify the user journey and onboard easily while leveraging the advantages of ERC-4337.
Here is how to add smart accounts creation and usage in your dApp in very few steps.
In this article, we’ll walk you through the development of the below demo together:
The full codebase is available here: https://github.com/trustwallet/trustsmartaccdemo
For New Projects
If you're creating a new project, follow these steps:
Step 1: Setup Your Project
First, set up a new React project.
pnpm create wagmi
pnpm install && pnpm run dev
cd [PROJECT NAME]
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";
const App: 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 (
<div className="p-12">
<div className="max-w-md mx-auto items-center flex">
<a href="#" className="mx-auto">
<img src={Logo} alt="Trust Wallet" className="inline-block w-48" />
</a>
</div>
<div className="mt-8 space-y-4 shadow-lg rounded-lg overflow-hidden max-w-md mx-auto bg-white">
<div className="p-8 flex flex-col justify-center items-center">
<h1 className="mt-4 text-2xl font-semibold text-center">
Trust Smart Account Demo
</h1>
<p className="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>
<Card
step={step}
index={1}
title="Connect your wallet"
description={address ? `Signer ${address} is connected!` : ""}
/>
{step === 0 && (
<SignerConnect connectors={connectors} connect={connect} />
)}
<Card
step={step}
index={2}
title="Create or retrieve your Smart account"
description={
smartAccount
? `Your Trust Smart Account ${smartAccount.account.address} is Ready!`
: ""
}
/>
{step === 1 && (
<SmartAccountCreate
smartAccount={smartAccount}
setSmartAccount={setSmartAccount}
/>
)}
<Card
step={step}
index={3}
title="Mint NFT"
description="NFT is Gasless"
/>
{step === 2 && (
<NFTMint smartAccount={smartAccount} setMintTx={setMintTx} />
)}
{mintTx && (
<div className="p-8 text-center">
<a
href={`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>
);
};
export default 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.
Resources
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 .