@@ -9,11 +9,15 @@ import {
99 type Address ,
1010} from "thirdweb" ;
1111import { transfer as transferERC20 } from "thirdweb/extensions/erc20" ;
12- import { isContractDeployed , resolvePromisedValue } from "thirdweb/utils" ;
12+ import { isContractDeployed } from "thirdweb/utils" ;
1313import { getChain } from "../../../shared/utils/chain" ;
14- import { normalizeAddress } from "../../../shared/utils/primitive-types" ;
14+ import {
15+ getChecksumAddress ,
16+ normalizeAddress ,
17+ } from "../../../shared/utils/primitive-types" ;
1518import { thirdwebClient } from "../../../shared/utils/sdk" ;
1619import { insertTransaction } from "../../../shared/utils/transaction/insert-transaction" ;
20+ import { queueTransaction } from "../../../shared/utils/transaction/queue-transation" ;
1721import type { InsertedTransaction } from "../../../shared/utils/transaction/types" ;
1822import { createCustomError } from "../../middleware/error" ;
1923import { AddressSchema } from "../../schemas/address" ;
@@ -25,7 +29,7 @@ import {
2529} from "../../schemas/shared-api-schemas" ;
2630import { txOverridesWithValueSchema } from "../../schemas/tx-overrides" ;
2731import {
28- walletHeaderSchema ,
32+ walletWithAAHeaderSchema ,
2933 walletWithAddressParamSchema ,
3034} from "../../schemas/wallet" ;
3135import { getChainIdFromChain } from "../../utils/chain" ;
@@ -70,7 +74,7 @@ export async function transfer(fastify: FastifyInstance) {
7074 operationId : "transfer" ,
7175 params : requestSchema ,
7276 body : requestBodySchema ,
73- headers : walletHeaderSchema ,
77+ headers : walletWithAAHeaderSchema ,
7478 querystring : requestQuerystringSchema ,
7579 response : {
7680 ...standardResponseSchema ,
@@ -88,31 +92,50 @@ export async function transfer(fastify: FastifyInstance) {
8892 const {
8993 "x-backend-wallet-address" : walletAddress ,
9094 "x-idempotency-key" : idempotencyKey ,
95+ "x-account-address" : accountAddress ,
96+ "x-account-factory-address" : accountFactoryAddress ,
97+ "x-account-salt" : accountSalt ,
9198 "x-transaction-mode" : transactionMode ,
92- } = request . headers as Static < typeof walletHeaderSchema > ;
99+ } = request . headers as Static < typeof walletWithAAHeaderSchema > ;
93100 const { simulateTx : shouldSimulate } = request . query ;
94101
95102 // Resolve inputs.
96103 const currencyAddress = normalizeAddress ( _currencyAddress ) ;
97104 const chainId = await getChainIdFromChain ( chain ) ;
98105
99- let insertedTransaction : InsertedTransaction ;
106+ let queueId : string ;
100107 if (
101108 currencyAddress === ZERO_ADDRESS ||
102109 currencyAddress === NATIVE_TOKEN_ADDRESS
103110 ) {
104- insertedTransaction = {
105- isUserOp : false ,
111+ // Native token transfer - use insertTransaction directly
112+ const insertedTransaction : InsertedTransaction = {
106113 chainId,
107114 from : walletAddress as Address ,
108115 to : to as Address ,
109116 data : "0x" ,
110117 value : toWei ( amount ) ,
111- extension : "none" ,
112- functionName : "transfer" ,
113118 transactionMode,
114119 ...parseTransactionOverrides ( txOverrides ) ,
120+ ...( accountAddress
121+ ? {
122+ isUserOp : true ,
123+ accountAddress : getChecksumAddress ( accountAddress ) ,
124+ signerAddress : getChecksumAddress ( walletAddress ) ,
125+ target : getChecksumAddress ( to ) ,
126+ accountFactoryAddress : getChecksumAddress (
127+ accountFactoryAddress ,
128+ ) ,
129+ accountSalt,
130+ }
131+ : { isUserOp : false } ) ,
115132 } ;
133+
134+ queueId = await insertTransaction ( {
135+ insertedTransaction,
136+ idempotencyKey,
137+ shouldSimulate,
138+ } ) ;
116139 } else {
117140 const contract = getContract ( {
118141 client : thirdwebClient ,
@@ -131,31 +154,25 @@ export async function transfer(fastify: FastifyInstance) {
131154 ) ;
132155 }
133156
157+ // ERC20 token transfer - use queueTransaction with PreparedTransaction
134158 const transaction = transferERC20 ( { contract, to, amount } ) ;
135159
136- insertedTransaction = {
137- isUserOp : false ,
138- chainId ,
139- from : walletAddress as Address ,
140- to : ( await resolvePromisedValue ( transaction . to ) ) as
141- | Address
142- | undefined ,
143- data : await resolvePromisedValue ( transaction . data ) ,
144- value : 0n ,
145- extension : "erc20" ,
160+ queueId = await queueTransaction ( {
161+ transaction ,
162+ fromAddress : getChecksumAddress ( walletAddress ) ,
163+ toAddress : getChecksumAddress ( to ) ,
164+ accountAddress : getChecksumAddress ( accountAddress ) ,
165+ accountFactoryAddress : getChecksumAddress ( accountFactoryAddress ) ,
166+ accountSalt ,
167+ txOverrides ,
168+ idempotencyKey ,
169+ shouldSimulate ,
146170 functionName : "transfer" ,
147- functionArgs : [ to , amount , currencyAddress ] ,
171+ extension : "erc20" ,
148172 transactionMode,
149- ...parseTransactionOverrides ( txOverrides ) ,
150- } ;
173+ } ) ;
151174 }
152175
153- const queueId = await insertTransaction ( {
154- insertedTransaction,
155- idempotencyKey,
156- shouldSimulate,
157- } ) ;
158-
159176 reply . status ( StatusCodes . OK ) . send ( {
160177 result : {
161178 queueId,
0 commit comments