11"use server" ;
22
3- import { Engine } from "@thirdweb-dev/engine" ;
4-
3+ import { Engine , defineChain , encode , getContract } from "thirdweb" ;
4+ import { multicall } from "thirdweb/extensions/common" ;
5+ import * as ERC20 from "thirdweb/extensions/erc20" ;
6+ import * as ERC1155 from "thirdweb/extensions/erc1155" ;
7+ import { THIRDWEB_CLIENT } from "../../lib/client" ;
58const BACKEND_WALLET_ADDRESS = process . env . ENGINE_BACKEND_WALLET as string ;
9+ const ENGINE_VAULT_ACCESS_TOKEN = process . env
10+ . ENGINE_VAULT_ACCESS_TOKEN as string ;
611
7- const engine = new Engine ( {
8- url : process . env . ENGINE_URL as string ,
9- accessToken : process . env . ENGINE_ACCESS_TOKEN as string ,
12+ const serverWallet = Engine . serverWallet ( {
13+ address : BACKEND_WALLET_ADDRESS ,
14+ client : THIRDWEB_CLIENT ,
15+ vaultAccessToken : ENGINE_VAULT_ACCESS_TOKEN ,
1016} ) ;
1117
1218export async function airdrop_tokens_with_engine ( params : {
@@ -17,20 +23,37 @@ export async function airdrop_tokens_with_engine(params: {
1723 amount : string ;
1824 } [ ] ;
1925} ) {
20- const res = await engine . erc20 . mintBatchTo (
21- params . chainId . toString ( ) ,
22- params . contractAddress ,
23- BACKEND_WALLET_ADDRESS ,
24- {
25- data : params . receivers ,
26- } ,
26+ const contract = getContract ( {
27+ address : params . contractAddress ,
28+ chain : defineChain ( params . chainId ) ,
29+ client : THIRDWEB_CLIENT ,
30+ } ) ;
31+ const data = await Promise . all (
32+ params . receivers . map ( ( receiver ) =>
33+ encode (
34+ ERC20 . mintTo ( {
35+ contract,
36+ to : receiver . toAddress ,
37+ amount : receiver . amount ,
38+ } ) ,
39+ ) ,
40+ ) ,
2741 ) ;
42+ const tx = multicall ( {
43+ contract,
44+ data,
45+ } ) ;
46+
47+ const res = await serverWallet . enqueueTransaction ( { transaction : tx } ) ;
2848
29- return res . result ;
49+ return res . transactionId ;
3050}
3151
3252export async function get_engine_tx_status ( queueId : string ) {
33- const status = await engine . transaction . status ( queueId ) ;
53+ const status = await Engine . getTransactionStatus ( {
54+ client : THIRDWEB_CLIENT ,
55+ transactionId : queueId ,
56+ } ) ;
3457 return status ;
3558}
3659
@@ -49,17 +72,19 @@ type MintNFTParams = {
4972} ;
5073
5174export async function mint_erc1155_nft_with_engine ( params : MintNFTParams ) {
52- const res = await engine . erc1155 . mintTo (
53- params . chainId . toString ( ) ,
54- params . contractAddress ,
55- BACKEND_WALLET_ADDRESS ,
56- {
57- receiver : params . toAddress ,
58- metadataWithSupply : params . metadataWithSupply ,
59- } ,
60- ) ;
75+ const tx = ERC1155 . mintTo ( {
76+ contract : getContract ( {
77+ address : params . contractAddress ,
78+ chain : defineChain ( params . chainId ) ,
79+ client : THIRDWEB_CLIENT ,
80+ } ) ,
81+ nft : params . metadataWithSupply . metadata ,
82+ to : params . toAddress ,
83+ supply : BigInt ( params . metadataWithSupply . supply ) ,
84+ } ) ;
85+ const res = await serverWallet . enqueueTransaction ( { transaction : tx } ) ;
6186
62- return res . result ;
87+ return res . transactionId ;
6388}
6489
6590type ClaimNFTParams = {
@@ -71,16 +96,17 @@ type ClaimNFTParams = {
7196} ;
7297
7398export async function claim_erc1155_nft_with_engine ( params : ClaimNFTParams ) {
74- const res = await engine . erc1155 . claimTo (
75- params . chainId . toString ( ) ,
76- params . contractAddress ,
77- BACKEND_WALLET_ADDRESS ,
78- {
79- receiver : params . receiverAddress ,
80- quantity : params . quantity . toString ( ) ,
81- tokenId : params . tokenId ,
82- } ,
83- ) ;
99+ const tx = ERC1155 . claimTo ( {
100+ contract : getContract ( {
101+ address : params . contractAddress ,
102+ chain : defineChain ( params . chainId ) ,
103+ client : THIRDWEB_CLIENT ,
104+ } ) ,
105+ to : params . receiverAddress ,
106+ tokenId : BigInt ( params . tokenId ) ,
107+ quantity : BigInt ( params . quantity ) ,
108+ } ) ;
109+ const res = await serverWallet . enqueueTransaction ( { transaction : tx } ) ;
84110
85- return res . result ;
111+ return res . transactionId ;
86112}
0 commit comments