Skip to content

Commit 60e7c68

Browse files
fix: remove invalid ScVal import
1 parent d8fd73d commit 60e7c68

1 file changed

Lines changed: 29 additions & 18 deletions

File tree

frontend/src/lib/contract/soroban-client.ts

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { STELLAR_NETWORK, CONTRACT_ID } from "@/lib/env";
2-
import type { Account, ScVal } from "@stellar/stellar-sdk";
2+
import type { Account } from "@stellar/stellar-sdk";
33

44
let rpcClient: unknown = null;
55

@@ -30,24 +30,28 @@ export async function simulateContractCall(
3030
method: string,
3131
args: unknown[] = []
3232
): Promise<unknown> {
33-
const { Contract, TransactionBuilder, Keypair, Networks, nativeToScVal, scValToNative } = await import(
34-
"@stellar/stellar-sdk"
35-
);
33+
const {
34+
Contract,
35+
TransactionBuilder,
36+
Keypair,
37+
nativeToScVal,
38+
scValToNative,
39+
} = await import("@stellar/stellar-sdk");
40+
3641
const client = await getSorobanClient();
3742
const contractId = getContractAddress();
3843

3944
try {
40-
// Create a temporary keypair for building the transaction
41-
// This is just for transaction construction; we won't actually sign it
4245
const tempKeypair = Keypair.random();
43-
44-
// Get the account details from RPC
45-
const sourceAccount = await (client as { getAccount: (key: string) => Promise<Account> }).getAccount(tempKeypair.publicKey());
4646

47-
// Create contract instance and add operation
47+
const sourceAccount = await (
48+
client as {
49+
getAccount: (key: string) => Promise<Account>;
50+
}
51+
).getAccount(tempKeypair.publicKey());
52+
4853
const contract = new Contract(contractId);
49-
50-
// Build the contract call operation with arguments
54+
5155
const operation = contract.call(
5256
method,
5357
...args.map((arg) => {
@@ -64,7 +68,6 @@ export async function simulateContractCall(
6468
})
6569
);
6670

67-
// Build transaction
6871
const tx = new TransactionBuilder(sourceAccount, {
6972
fee: "100",
7073
networkPassphrase: STELLAR_NETWORK.networkPassphrase,
@@ -73,17 +76,25 @@ export async function simulateContractCall(
7376
.setTimeout(30)
7477
.build();
7578

76-
// Prepare transaction (which includes simulation)
77-
const preparedTx = await (client as { prepareTransaction: (tx: unknown) => Promise<unknown> }).prepareTransaction(tx);
79+
const preparedTx = await (
80+
client as {
81+
prepareTransaction: (tx: unknown) => Promise<unknown>;
82+
}
83+
).prepareTransaction(tx);
84+
85+
const result = (
86+
preparedTx as {
87+
result?: { retval: unknown };
88+
}
89+
).result?.retval;
7890

79-
// Extract result from prepared transaction
80-
const result = (preparedTx as { result?: { retval: ScVal } }).result?.retval;
8191
if (result) {
8292
return scValToNative(result);
8393
}
94+
8495
return null;
8596
} catch (error) {
8697
console.error("Simulation error:", error);
8798
throw error;
8899
}
89-
}
100+
}

0 commit comments

Comments
 (0)