Class ContractClient

java.lang.Object
org.stellar.sdk.contract.ContractClient
All Implemented Interfaces:
Closeable, AutoCloseable

public class ContractClient extends Object implements Closeable
A client to interact with Soroban smart contracts.

This client is a wrapper for SorobanServer and TransactionBuilder to make it easier to interact with Soroban smart contracts. If you need more fine-grained control, please consider using them directly.

  • Constructor Details

    • ContractClient

      public ContractClient(String contractId, String rpcUrl, Network network)
      Creates a new ContractClient with the given contract ID, RPC URL, and network.
      Parameters:
      contractId - The contract ID to interact with.
      rpcUrl - The RPC URL of the Soroban server.
      network - The network to interact with.
  • Method Details

    • invoke

      public <T> AssembledTransaction<T> invoke(String functionName, List<SCVal> parameters, String source, KeyPair signer, Function<SCVal,T> parseResultXdrFn, int baseFee)
      Parameters:
      functionName - The name of the function to invoke.
      parameters - The parameters to pass to the function.
      source - The source account to use for the transaction.
      signer - The key pair to sign the transaction with.
      parseResultXdrFn - A function to parse the result XDR of the transaction.
      baseFee - The base fee for the transaction.
    • invoke

      public <T> AssembledTransaction<T> invoke(String functionName, Collection<SCVal> parameters, String source, @Nullable KeyPair signer, @Nullable Function<SCVal,T> parseResultXdrFn, int baseFee, int transactionTimeout, int submitTimeout, boolean simulate, boolean restore)
      Build an AssembledTransaction to invoke a function on the contract.
      Parameters:
      functionName - The name of the function to invoke.
      parameters - The parameters to pass to the function.
      source - The source account to use for the transaction.
      signer - The key pair to sign the transaction with.
      parseResultXdrFn - A function to parse the result XDR of the transaction.
      baseFee - The base fee for the transaction.
      transactionTimeout - The timeout for the transaction.
      submitTimeout - The timeout for submitting the transaction.
      simulate - Whether to simulate the transaction.
      restore - Whether to restore the transaction, only valid when simulate is true, and the signer is provided.
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException