Skip to content

Interact with contracts: upload, instantiate and call commands

Sergej Kostjucenko requested to merge aj-contract-call into master

Created by: ascjones

Adds upload, instantiate and call commands which allows interacting with contracts on live chains with a compatible pallet-contracts.

Upload

cargo contract upload --suri //Alice --dry-run

image

cargo contract upload --suri //Alice

image

Instantiate

cargo contract instantiate \
       --constructor new \
       --args false \
       --suri //Alice \
       --code-hash 0xbc1b42256696c8a4187ec3ed79fc602789fc11287c4c30926f5e31ed8169574e \
       --dry-run

image

cargo contract instantiate \
       --constructor new \
       --args false \
       --suri //Alice \
       --code-hash 0xbc1b42256696c8a4187ec3ed79fc602789fc11287c4c30926f5e31ed8169574e

image

Instantiate with code

Omitting --code-hash will call instantiate_with_code:

image

Call

cargo contract call \
       --contract 5FQNUFjuSxjB1o67CneHXieB1Hy6xAj2A4h4dUVLCvNkgRmD \
       --message flip \
       --suri //Alice \
       --dry-run

image

cargo contract call \
       --contract 5FQNUFjuSxjB1o67CneHXieB1Hy6xAj2A4h4dUVLCvNkgRmD \
       --message flip \
       --suri //Alice

image

cargo contract call \
       --contract 5FQNUFjuSxjB1o67CneHXieB1Hy6xAj2A4h4dUVLCvNkgRmD \
       --message get \
       --suri //Alice \
       --dry-run

Debug message

If the contract is build in debug mode then

image

Will result in...

image

Todo

  • Display all events resulting from Call
  • Optional 0x prefix for hex encoded code hash
  • SS58 AccountIds
  • Release and use pallet-contracts-primitives and sp-rpc from crates.io
  • Documentation
    • CLI usage help
    • extrinsics.md
    • transcoding/scon code docs

Follow ups

These will be promoted to their own issue, or into separate issues for following up once this is merged.

Merge request reports