go icon indicating copy to clipboard operation
go copied to clipboard

Invoke a contract using Soroban CLI

Open tsachiherman opened this issue 2 years ago • 1 comments

Invoke a contract using Soroban CLI

tsachiherman avatar Oct 03 '22 17:10 tsachiherman

blocked by https://github.com/stellar/go/pull/4621

tsachiherman avatar Oct 03 '22 17:10 tsachiherman

will try out e2e steps with new builds of quickstart/soroban-rpc/cli given new core version 19.4.1-1093.9a33c7392.focal~soroban

sreuland avatar Oct 04 '22 20:10 sreuland

success! this used a format of invoke that includes --wasm to the original contract wasm bin file and the --id which is obtained by first doing a deploy of the same wasm bin file.

# first make sure to have built soroban 'cli' tool locally
$ git clone https://github.com/stellar/soroban-cli.git
$ cd soroban-cli
$ cargo install --path .
$ cd ..

# run docker image stellar/quickstart:pr-373-soroban-dev in the background
$ docker pull stellar/quickstart:pr-373-soroban-dev
$ docker run --rm -ti \
  -p 8000:8000 \
  stellar/quickstart:pr-373-soroban-dev \
  --standalone --enable-soroban-rpc --protocol-version 20

#  git clone https://github.com/stellar/soroban-examples.git; cd soroban-examples

# Build the hello world contract with those dependencies
$ make clean
$ (cd hello_world ; cargo build --target wasm32-unknown-unknown --release)

# Deploy the contract
$ soroban deploy \
  --wasm target/wasm32-unknown-unknown/release/soroban_hello_world_contract.wasm \
  --rpc-url http://localhost:8000/soroban/rpc \
  --secret-key <secret key of root account in standalone quickstart> \
  --network-passphrase "Standalone Network ; February 2017" \
  --salt 0

# it will display output on console with the Contract ID, need that for next step:
$ Contract ID: 1f3eb7b8dc051d6aa46db5454588a142c671a0cdcdb36a2f754d9675a64bf613

# Invoke the 'hello' function on the contract using cli
# for now, make sure no spaces, ascii=32, in the --arg value
# this will display the function response in console output
$ soroban invoke --wasm target/wasm32-unknown-unknown/release/soroban_hello_world_contract.wasm --fn hello --arg="comoestas" --rpc-url http://localhost:8000/soroban/rpc --secret-key <secret key of root account in standalone quickstart> --network-passphrase "Standalone Network ; February 2017" --id 1f3eb7b8dc051d6aa46db5454588a142c671a0cdcdb36a2f754d9675a64bf613
$ success
$ ["Hello","comoestas"]                                              

sreuland avatar Oct 05 '22 02:10 sreuland

leaving in review, we are going to re-test this with updated cli that outputs tx results after invoke.

sreuland avatar Oct 05 '22 16:10 sreuland

@2opremio , @tamirms and I did a group pairing session and retested the cli invoke sequence following the steps, there was some json parsing issue discovered between soroban-rpc and cli, that was changed on soroban-rpc , after which the test passed:

$ soroban invoke --wasm target/wasm32-unknown-unknown/release/soroban_hello_world_contract.wasm --fn hello --arg="comoestas" --rpc-server-url http://localhost:8000/soroban/rpc --secret-key SC5O7VZUXDJ6JBDSZ74DSERXL7W3Y5LTOAMRF7RQRL3TAGAPS7LUVG3L --network-passphrase "Standalone Network ; February 2017" --id 1f3eb7b8dc051d6aa46db5454588a142c671a0cdcdb36a2f754d9675a64bf613
success
["Hello","comoestas"]

it's important to follow those scripted steps verbatim and re-pull and rebuild everything mentioned, as changes are often and if components are on different rev's from what version core is on in the quickstart image(19.4.1-1097.4e813f20e.focal~soroban as of this test), otherwise will get problems later.

also, no spaces in the arg field allowed, reference here - https://github.com/stellar/soroban-cli/issues/187

sreuland avatar Oct 06 '22 18:10 sreuland