-
Notifications
You must be signed in to change notification settings - Fork 95
feat: Enhance UI components and implement Soroban contract invocation #670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Abdullahi130
wants to merge
1
commit into
OpenKnight-Foundation:main
Choose a base branch
from
Abdullahi130:feature/web3-ui-enhancements
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: NOVUS-X/XLMate
Length of output: 111
🏁 Script executed:
Repository: NOVUS-X/XLMate
Length of output: 2324
🏁 Script executed:
rg -n "import.*stellar-sdk|from.*stellar-sdk" frontend/context/walletContext.tsxRepository: NOVUS-X/XLMate
Length of output: 271
🏁 Script executed:
rg -n "invokeSorobanContract" frontend/context/walletContext.tsx -A 40Repository: NOVUS-X/XLMate
Length of output: 4378
🏁 Script executed:
Repository: NOVUS-X/XLMate
Length of output: 719
🌐 Web query:
stellar-sdk 10.4.0 contract.call xdr.ScVal parameters💡 Result:
In stellar-sdk version 10.4.0 (specifically
@stellar/stellar-sdk), the Contract.call method is used to invoke a Soroban smart contract function and returns an xdr.Operation for InvokeHostFunctionOp. Method signature: contract.call(method: string, ...params: xdr.ScVal[]): xdr.Operation Parameters: - method: string - Name of the contract method to call. - ...params: xdr.ScVal[] - Variable number of xdr.ScVal arguments to pass to the function. Each parameter must be a properly constructed xdr.ScVal instance matching the contract function's expected input types. Usage example: const contract = new Contract("CA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAXE"); const op = contract.call("increment", xdr.ScVal.scvU32(5)); The SDK provides nativeToScVal and related utilities (via Contract.Spec) to convert JavaScript native values (numbers, strings, objects, arrays, etc.) to xdr.ScVal instances. For example: - Numbers: nativeToScVal(123, {type: 'u32'}) → xdr.ScVal.scvU32(123) - Addresses: Address.fromString("G...").toScVal - Strings: nativeToScVal("hello") → xdr.ScVal.scvString("hello") - Maps/Vecs: Automatically converted from objects/arrays with optional type hints. This API has remained stable across versions including 10.4.0, as confirmed by the official documentation and changelog. For full conversion details, see the scval.js source which handles type inference and validation.Citations:
🌐 Web query:
stellar-sdk 10.4.0 TransactionBuilder.assembleTransaction signature networkPassphrase💡 Result:
In
@stellar/stellar-sdkversion 10.4.0, TransactionBuilder does not have a direct method called assembleTransaction. The assembleTransaction function is a static utility in the rpc module that takes a raw Transaction or FeeBumpTransaction and a simulation response (Api.SimulateTransactionResponse or Api.RawSimulateTransactionResponse), returning a new TransactionBuilder with applied Soroban auth, resources, and adjusted fee. The networkPassphrase is preserved from the input raw transaction via TransactionBuilder.cloneFrom(raw, {..., networkPassphrase: raw.networkPassphrase}). Signature: assembleTransaction(raw: Transaction | FeeBumpTransaction, simulation: Api.SimulateTransactionResponse | Api.RawSimulateTransactionResponse): TransactionBuilder Usage example from source: const txnBuilder = TransactionBuilder.cloneFrom(raw, { fee: classicFeeNum.toString, sorobanData: success.transactionData.build, networkPassphrase: raw.networkPassphrase }); This is used in Soroban transaction preparation after simulateTransaction, typically via SorobanServer.prepareTransaction which internally calls it. The networkPassphrase ensures signatures are valid for the correct network (e.g., "Public Global Stellar Network ; September 2015" for mainnet).Citations:
🌐 Web query:
stellar-sdk 10.4.0 SorobanRpc.Api.isSimulationError💡 Result:
SorobanRpc.Api.isSimulationError is a static method in the
@stellar/stellar-sdkJavaScript library (available in version 10.4.0 and later) that checks if a Soroban RPC simulateTransaction response indicates an error. It returns true if the simulation failed (e.g., the response has an 'error' field), and false otherwise. This method is used in typical Soroban transaction workflows to validate simulation results before assembling and submitting transactions. For example: if (SorobanRpc.Api.isSimulationError(sim)) { throw sim.error; // or handle the error } It pairs with related methods like SorobanRpc.Api.isSimulationSuccess (checks for successful simulation) and SorobanRpc.Api.isSimulationRestore (checks if footprint restoration is needed). The method is part of the rpc.Api namespace, imported as: import { SorobanRpc } from '@stellar/stellar-sdk'; Note: In newer SDK versions (post-v12), the import path may be '@stellar/stellar-sdk/rpc' for the Api, but the functionality remains the same. Version 10.4.0 specifically includes Soroban RPC support via updates to stellar-base.Citations:
error: invalid version byte. expected 48, got 16trying toauthorizeEntrystellar/js-stellar-sdk#1020🌐 Web query:
stellar-sdk 10.4.0 SorobanRpc namespace import rpc module💡 Result:
In stellar-sdk version 10.4.0, the Soroban RPC functionality is accessed via the SorobanRpc namespace. To import the rpc module (which provides the Soroban RPC Server, API types, and helpers like assembleTransaction), use: import { SorobanRpc } from 'stellar-sdk'; Then destructure as needed: const { Server, Api, assembleTransaction } = SorobanRpc; Example usage: const server = new SorobanRpc.Server('https://soroban-testnet.stellar.org'); This structure was established around v11.0.0 but was present in v10.4.0 per the changelog mentioning v10.4.0 and migration guides referencing SorobanRpc. In later versions (post-v11), SorobanRpc was deprecated in favor of a top-level rpc export: import { rpc } from '@stellar/stellar-sdk'; Note: The package transitioned to
@stellar/stellar-sdkscoped name starting around v11+, but v10.4.0 uses the unscoped stellar-sdk. Always check your bundler for tree-shaking with named imports.Citations:
🌐 Web query:
stellar-sdk 10.4.0 "new Server" SOROBAN_RPC vs SorobanRpc.Server💡 Result:
In the stellar-sdk JavaScript/TypeScript library (likely
@stellar/stellar-sdk, as the legacy 'stellar-sdk' package reached v13.x), the primary way to create a Soroban RPC client (now Stellar RPC) is via new Server(url, options), where Server is from the rpc module. SorobanRpc.Server refers to the Server class in the SorobanRpc namespace, used in older or specific contexts like the deprecated js-soroban-client library. Example: new SorobanRpc.Server('http://localhost:8000/soroban/rpc'). "SOROBAN_RPC" likely refers to the Soroban RPC protocol or environment variable/constant, while new Server is the constructor call for the client. No specific changes or differences are noted in version 10.4.0 (which exists in the old stellar-sdk package per changelogs), as RPC client usage has remained consistent: const server = new StellarSdk.rpc.Server(rpcUrl); or similar import. Official docs confirm new Server(serverURL) for RPC connections, with options like {allowHttp: true} for local dev. Soroban RPC was renamed to Stellar RPC in late 2024, but SDK classes retained naming. Usage example: import * as StellarSdk from '@stellar/stellar-sdk'; const server = new StellarSdk.rpc.Server('https://soroban-testnet.stellar.org'); No evidence of breaking changes to this API in recent versions; it's the standard constructor.Citations:
Fix critical API breakage in Soroban transaction flow.
contract.call()requiresxdr.ScVal[]arguments (Line 265): Currently passingany[]directly. The method signature iscontract.call(method: string, ...params: xdr.ScVal[]). Each argument must be a properly constructedxdr.ScValinstance (e.g.,xdr.ScVal.scvU32(5)for numbers). Raw JS values will fail simulation. Change parameter type fromany[]toxdr.ScVal[]and require callers to pre-convert using SDK utilities likenativeToScVal.assembleTransaction()call is broken (Line 281): The method is in therpcmodule, notTransactionBuilder. Correct signature isSorobanRpc.assembleTransaction(tx, simulatedTx)(two arguments only;networkPassphraseis implicitly preserved from the transaction). The current three-argument call will throw at runtime. ReplaceTransactionBuilder.assembleTransaction(tx, NETWORK_PASSPHRASE, simulatedTx as any).build()withSorobanRpc.assembleTransaction(tx, simulatedTx).build().Use
SorobanRpc.Api.isSimulationError()for error checking (Line 272): Replace the manual check with the SDK's discriminated union helper:if (SorobanRpc.Api.isSimulationError(simulatedTx)).Also update imports to use
SorobanRpcnamespace:import { SorobanRpc, ... } from "stellar-sdk"and usenew SorobanRpc.Server(SOROBAN_RPC, { allowHttp: true })instead of plainnew Server().🔧 Proposed fix
const invokeSorobanContract = async ( contractId: string, functionName: string, - args: any[] = [], + args: xdr.ScVal[] = [], ) => { if (!address) throw new Error("No wallet connected"); try { - // Dynamic import to avoid build-time issues - const { Contract, TimeoutInfinite } = await import("stellar-sdk"); - - // Use the Soroban RPC - const rpcServer = new Server(SOROBAN_RPC, { allowHttp: true }); + const rpcServer = new SorobanRpc.Server(SOROBAN_RPC, { allowHttp: true }); const acct = await rpcServer.getAccount(address); const contract = new Contract(contractId); let tx = new TransactionBuilder(acct, { fee: "10000", networkPassphrase: NETWORK_PASSPHRASE, }) .addOperation(contract.call(functionName, ...args)) .setTimeout(TimeoutInfinite) .build(); const simulatedTx = await rpcServer.simulateTransaction(tx); - if ("error" in simulatedTx && simulatedTx.error) { + if (SorobanRpc.Api.isSimulationError(simulatedTx)) { throw new Error(`Simulation failed: ${simulatedTx.error}`); } - // Assemble transaction with simulation data - if (!simulatedTx.transactionData) { - throw new Error("Simulation failed: missing transactionData"); - } - - tx = TransactionBuilder.assembleTransaction(tx, NETWORK_PASSPHRASE, simulatedTx as any).build(); + tx = SorobanRpc.assembleTransaction(tx, simulatedTx).build();Also update imports (top of file):
And import
ContractandTimeoutInfinitestatically or ensure they come from the right namespace.🤖 Prompt for AI Agents