#Contract Function Invoke on Golang SDK

5 messages · Page 1 of 1 (latest)

pseudo flicker
#

Hi there, I have a question regarding invoking contract function via Golang backend.

I'm actually looking for examples on how to invoke the contract on Golang
Currently, the package I use is https://github.com/stellar/go, and after reading the docs, I assume I can utilize the InvokeHostFunction.
Are there any docs or github example on this?

Or are there any preferable method on how to get this done?

Thanks!

steel nexus
#

@maiden apex @rugged sand do you know or can you tag someone who may know the answer to this?

maiden apex
#

@prime pollen maybe you would know? Are there any docs for our Go repo? I've personally never used it. My understanding was this repo was more for the Horizon service vs a general purpose SDK but maybe I'm wrong?

prime pollen
#

Hi @pseudo flicker !

We don't have explicit docs for submitting Soroban transactions with Golang, but, in a nutshell I suggest to:

  1. build transactions using the txnbuild library: https://github.com/stellar/go/tree/master/txnbuild (yes InvokeHostFunction is what you want to use for Soroban)
  2. preflight the resulting transaction with Soroban RPC's simulateTransaction endpoint: https://soroban.stellar.org/api/methods/simulateTransaction
  3. submit the prefllight'ed transaction with https://soroban.stellar.org/api/methods/sendTransaction
  4. check the transaction was successful (
    or not) with https://soroban.stellar.org/api/methods/getTransaction

It is not super user-friendly (it's not meant as documentation), but you can use the soroban-integration tests as an example: https://github.com/stellar/soroban-tools/blob/main/cmd/soroban-rpc/internal/test/transaction_test.go#L48

#

Let me know if you have any specific questions!