1- // @ts -nocheck
21import { STELLAR_NETWORK , CONTRACT_ID } from "@/lib/env" ;
32
4- let rpcClient : any = null ;
3+ type SorobanRpcServer = {
4+ getAccount : ( id : string ) => Promise < unknown > ;
5+ simulateTransaction : ( tx : unknown ) => Promise < unknown > ;
6+ } ;
57
6- export async function getSorobanClient ( ) : Promise < any > {
8+ let rpcClient : SorobanRpcServer | null = null ;
9+
10+ export async function getSorobanClient ( ) : Promise < SorobanRpcServer > {
711 if ( ! rpcClient ) {
812 // Dynamic import to avoid TypeScript resolution issues
913 const { SorobanRpc } = await import ( "@stellar/stellar-sdk" ) ;
@@ -25,14 +29,14 @@ export function getContractAddress(): string {
2529
2630export interface InvokeContractOptions {
2731 method : string ;
28- args ?: any [ ] ;
29- signers ?: any [ ] ;
32+ args ?: unknown [ ] ;
33+ signers ?: unknown [ ] ;
3034}
3135
3236export async function simulateContractCall (
3337 method : string ,
34- args : any [ ] = [ ]
35- ) : Promise < any > {
38+ args : unknown [ ] = [ ]
39+ ) : Promise < unknown > {
3640 const { Address, TransactionBuilder, contract, nativeToScVal, scValToNative, SorobanRpc } = await import (
3741 "@stellar/stellar-sdk"
3842 ) ;
@@ -44,7 +48,7 @@ export async function simulateContractCall(
4448 const source = await client . getAccount ( contractId ) ;
4549
4650 // Create a contract invocation with simulated parameters
47- const params = args . map ( ( arg : any ) => {
51+ const params = args . map ( ( arg ) => {
4852 if ( typeof arg === "string" ) {
4953 return nativeToScVal ( arg , { type : "string" } ) ;
5054 }
@@ -70,16 +74,17 @@ export async function simulateContractCall(
7074 const client_tx = await client . simulateTransaction ( tx ) ;
7175
7276 if ( SorobanRpc . Api . isSimulationSuccess ( client_tx ) ) {
73- const result = client_tx . result ?. retval ;
77+ const result = ( client_tx as { result ?: { retval : unknown } } ) . result ?. retval ;
7478 if ( result ) {
7579 return scValToNative ( result ) ;
7680 }
7781 return null ;
7882 } else if ( SorobanRpc . Api . isSimulationRestore ( client_tx ) ) {
7983 throw new Error ( "Contract needs restore" ) ;
8084 } else if ( SorobanRpc . Api . isSimulationError ( client_tx ) ) {
85+ const errorMsg = ( client_tx as { error ?: { message : string } } ) . error ?. message ;
8186 throw new Error (
82- `Simulation error: ${ client_tx . error ?. message || "Unknown error" } `
87+ `Simulation error: ${ errorMsg || "Unknown error" } `
8388 ) ;
8489 }
8590 } catch ( error ) {
0 commit comments