1- import { Static , Type } from "@sinclair/typebox" ;
2- import { FastifyInstance } from "fastify" ;
1+ import { Type , type Static } from "@sinclair/typebox" ;
2+ import type { FastifyInstance } from "fastify" ;
33import { StatusCodes } from "http-status-codes" ;
4- import { queueTx } from "../../../../../../db/transactions/queueTx" ;
5- import { getContract } from "../../../../../../utils/cache/getContract" ;
4+ import { getContract } from "thirdweb" ;
5+ import { mintTo } from "thirdweb/extensions/erc721" ;
6+ import type { NFTInput } from "thirdweb/utils" ;
7+ import { getChain } from "../../../../../../utils/chain" ;
8+ import { thirdwebClient } from "../../../../../../utils/sdk" ;
9+ import { queueTransaction } from "../../../../../../utils/transaction/queueTransation" ;
610import { AddressSchema } from "../../../../../schemas/address" ;
711import { nftOrInputSchema } from "../../../../../schemas/nft" ;
812import {
@@ -12,7 +16,11 @@ import {
1216 transactionWritesResponseSchema ,
1317} from "../../../../../schemas/sharedApiSchemas" ;
1418import { txOverridesWithValueSchema } from "../../../../../schemas/txOverrides" ;
15- import { walletWithAAHeaderSchema } from "../../../../../schemas/wallet" ;
19+ import {
20+ maybeAddress ,
21+ requiredAddress ,
22+ walletWithAAHeaderSchema ,
23+ } from "../../../../../schemas/wallet" ;
1624import { getChainIdFromChain } from "../../../../../utils/chain" ;
1725
1826// INPUTS
@@ -61,31 +69,58 @@ export async function erc721mintTo(fastify: FastifyInstance) {
6169 } ,
6270 } ,
6371 handler : async ( request , reply ) => {
64- const { chain, contractAddress } = request . params ;
72+ const { chain : _chain , contractAddress } = request . params ;
6573 const { simulateTx } = request . query ;
6674 const { receiver, metadata, txOverrides } = request . body ;
6775 const {
68- "x-backend-wallet-address" : walletAddress ,
76+ "x-backend-wallet-address" : fromAddress ,
6977 "x-account-address" : accountAddress ,
7078 "x-idempotency-key" : idempotencyKey ,
79+ "x-account-factory-address" : accountFactoryAddress ,
80+ "x-account-salt" : accountSalt ,
7181 } = request . headers as Static < typeof walletWithAAHeaderSchema > ;
7282
73- const chainId = await getChainIdFromChain ( chain ) ;
74- const contract = await getContract ( {
75- chainId,
76- contractAddress,
77- walletAddress,
78- accountAddress,
83+ const chainId = await getChainIdFromChain ( _chain ) ;
84+ const chain = await getChain ( chainId ) ;
85+
86+ const contract = getContract ( {
87+ chain,
88+ client : thirdwebClient ,
89+ address : contractAddress ,
7990 } ) ;
80- const tx = await contract . erc721 . mintTo . prepare ( receiver , metadata ) ;
8191
82- const queueId = await queueTx ( {
83- tx,
84- chainId,
85- simulateTx,
86- extension : "erc721" ,
87- idempotencyKey,
92+ // Backward compatibility: Transform the request body's v4 shape to v5.
93+ const nft : NFTInput | string =
94+ typeof metadata === "string"
95+ ? metadata
96+ : {
97+ name : metadata . name ?. toString ( ) ?? undefined ,
98+ description : metadata . description ?? undefined ,
99+ image : metadata . image ?? undefined ,
100+ animation_url : metadata . animation_url ?? undefined ,
101+ external_url : metadata . external_url ?? undefined ,
102+ background_color : metadata . background_color ?? undefined ,
103+ properties : metadata . properties ,
104+ } ;
105+ const transaction = mintTo ( {
106+ contract,
107+ to : receiver ,
108+ nft,
109+ } ) ;
110+
111+ const queueId = await queueTransaction ( {
112+ transaction,
113+ fromAddress : requiredAddress ( fromAddress , "x-backend-wallet-address" ) ,
114+ toAddress : maybeAddress ( contractAddress , "to" ) ,
115+ accountAddress : maybeAddress ( accountAddress , "x-account-address" ) ,
116+ accountFactoryAddress : maybeAddress (
117+ accountFactoryAddress ,
118+ "x-account-factory-address" ,
119+ ) ,
120+ accountSalt,
88121 txOverrides,
122+ idempotencyKey,
123+ shouldSimulate : simulateTx ,
89124 } ) ;
90125
91126 reply . status ( StatusCodes . OK ) . send ( {
0 commit comments