@@ -61,7 +61,11 @@ public static void main(String[] args) throws Exception {
6161 TransferTransaction tx = createTransferTransaction (client , recipientId );
6262 FeeEstimateResponse stateEstimate = estimateWithStateMode (client , tx );
6363 FeeEstimateResponse intrinsicEstimate = estimateWithIntrinsicMode (client , tx );
64- compareEstimates (stateEstimate , intrinsicEstimate );
64+ if (stateEstimate != null && intrinsicEstimate != null ) {
65+ compareEstimates (stateEstimate , intrinsicEstimate );
66+ } else {
67+ System .out .println ("\n === Skipping Comparison due to missing estimate ===" );
68+ }
6569 demonstrateTokenCreationEstimate (client );
6670
6771 client .close ();
@@ -100,18 +104,24 @@ private static TransferTransaction createTransferTransaction(Client client, Acco
100104 private static FeeEstimateResponse estimateWithStateMode (Client client , TransferTransaction tx ) throws Exception {
101105 System .out .println ("\n === Estimating Fees with STATE Mode ===" );
102106
103- FeeEstimateResponse stateEstimate = new FeeEstimateQuery ()
104- .setMode (FeeEstimateMode .STATE )
105- .setTransaction (tx )
106- .execute (client );
107-
108- printNetworkFee (stateEstimate );
109- printNodeFee (stateEstimate );
110- printServiceFee (stateEstimate );
111- printTotalFee (stateEstimate );
112- System .out .println ("\n High Volume Multiplier: " + stateEstimate .getHighVolumeMultiplier ());
113-
114- return stateEstimate ;
107+ try {
108+ FeeEstimateResponse stateEstimate = new FeeEstimateQuery ()
109+ .setMode (FeeEstimateMode .STATE )
110+ .setTransaction (tx )
111+ .execute (client );
112+
113+ printNetworkFee (stateEstimate );
114+ printNodeFee (stateEstimate );
115+ printServiceFee (stateEstimate );
116+ printTotalFee (stateEstimate );
117+ System .out .println ("\n High Volume Multiplier: " + stateEstimate .getHighVolumeMultiplier ());
118+
119+ return stateEstimate ;
120+ } catch (IllegalStateException e ) {
121+ System .err .println ("Failed to estimate fees with STATE mode: " + e .getMessage ());
122+ System .err .println ("This might be due to compatibility issues with the Mirror Node version." );
123+ return null ;
124+ }
115125 }
116126
117127 private static void printNetworkFee (FeeEstimateResponse estimate ) {
@@ -187,12 +197,16 @@ private static void demonstrateTokenCreationEstimate(Client client) throws Excep
187197 .freezeWith (client )
188198 .signWithOperator (client );
189199
190- FeeEstimateResponse tokenEstimate = new FeeEstimateQuery ()
191- .setMode (FeeEstimateMode .STATE )
192- .setTransaction (tokenTx )
193- .execute (client );
200+ try {
201+ FeeEstimateResponse tokenEstimate = new FeeEstimateQuery ()
202+ .setMode (FeeEstimateMode .STATE )
203+ .setTransaction (tokenTx )
204+ .execute (client );
194205
195- System .out .println ("Token Creation Estimated Fee: " + tokenEstimate .getTotal () + " tinycents" );
196- System .out .println ("Token Creation Estimated Fee: " + Hbar .fromTinybars (tokenEstimate .getTotal () / 100 ));
206+ System .out .println ("Token Creation Estimated Fee: " + tokenEstimate .getTotal () + " tinycents" );
207+ System .out .println ("Token Creation Estimated Fee: " + Hbar .fromTinybars (tokenEstimate .getTotal () / 100 ));
208+ } catch (IllegalStateException e ) {
209+ System .err .println ("Failed to estimate token creation fees: " + e .getMessage ());
210+ }
197211 }
198212}
0 commit comments