1+ import { Account , Provider , uint256 , CallData , Contract } from "starknet" ;
2+ import dotenv from "dotenv" ;
3+ dotenv . config ( ) ;
4+
5+ import abi from "../abi/registry.json" ;
6+
7+ const PRIVATE_KEY = process . env . PRIVATE_KEY ! ;
8+ const ACCOUNT_ADDRESS = process . env . ACCOUNT_ADDRESS ! ;
9+ const RPC_URL = process . env . RPC_URL ! ;
10+
11+ const ACCOUNT_CONTRACT = process . env . ACCOUNT_CONTRACT ! ;
12+ const IMPLEMENTATION_HASH = process . env . IMPLEMENTATION_HASH ! ;
13+ const TOKEN_CONTRACT = process . env . TOKEN_CONTRACT ! ;
14+ const SALT = process . env . SALT ! ;
15+ const CHAIN_ID = process . env . CHAIN_ID ! ;
16+
17+ const TOTAL_AMOUNT_TO_SEND = 0 ; // total amount to be split across token IDs
18+ const TOKEN_DECIMALS = 0 ; // adjust depending on the token's decimals
19+
20+ const TOKEN_IDS = [ 0 ] ; // replace with token IDs
21+
22+ async function main ( ) {
23+ const provider = new Provider ( { nodeUrl : RPC_URL } ) ;
24+ const account = new Account ( provider , ACCOUNT_ADDRESS , PRIVATE_KEY ) ;
25+
26+ const contract = new Contract ( abi , ACCOUNT_CONTRACT , provider ) ;
27+ contract . connect ( account ) ;
28+
29+ const amountPerAccount = TOTAL_AMOUNT_TO_SEND / TOKEN_IDS . length ;
30+ const amountInBaseUnits = BigInt ( Math . floor ( amountPerAccount * 10 ** TOKEN_DECIMALS ) ) ;
31+
32+ const txs : any [ ] = [ ] ;
33+
34+ for ( const tokenId of TOKEN_IDS ) {
35+ const address = await contract . call ( "get_account" , [
36+ IMPLEMENTATION_HASH ,
37+ TOKEN_CONTRACT ,
38+ uint256 . bnToUint256 ( tokenId ) ,
39+ SALT ,
40+ CHAIN_ID
41+ ] ) ;
42+
43+ console . log ( `Sending ${ amountPerAccount } tokens to account at ${ address } with token ID ${ tokenId } ` ) ;
44+
45+ const call = {
46+ contractAddress : "0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8" ,
47+ entrypoint : "transfer" ,
48+ calldata : CallData . compile ( [
49+ address ,
50+ uint256 . bnToUint256 ( amountInBaseUnits )
51+ ] )
52+ } ;
53+
54+ txs . push ( call ) ;
55+ }
56+
57+ const res = await account . execute ( txs ) ;
58+ console . log ( "Transaction hash:" , res . transaction_hash ) ;
59+ }
60+
61+ main ( ) . catch ( console . error ) ;
0 commit comments