Skip to content
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

Interact with contracts: upload, instantiate and call commands #79

Merged
merged 366 commits into from
Feb 16, 2022

Conversation

ascjones
Copy link
Collaborator

@ascjones ascjones commented Sep 22, 2020

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.

src/cmd/extrinsics/call.rs Outdated Show resolved Hide resolved
@ascjones ascjones marked this pull request as ready for review October 26, 2020 10:34
@@ -28,7 +28,7 @@ heck = "0.4.0"
zip = { version = "0.5.13", default-features = false }
parity-wasm = "0.42.2"
cargo_metadata = "0.14.1"
codec = { package = "parity-scale-codec", version = "2.3.1", features = ["derive"] }
scale = { package = "parity-scale-codec", version = "2.3.1", features = ["derive"] }
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed because I have an embedded contract for testing purposes and ink! generates code with ::scale imports.

Cargo.toml Outdated Show resolved Hide resolved
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Copy link
Contributor

@athei athei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I played around with it a bit and it is working as I imagined it. Some remarks:

Probably fix now

  • Remove trailing new line from debug message. It looks awkward with the quote on the next line.
  • Remove the decoding of the module error as long as this is buggy. It is massively confusing to see a wrong error there. Better to not decode.

Fix in follow up

  • Add support for remove_code extrinsic.

docs/extrinsics.md Outdated Show resolved Hide resolved
@ascjones
Copy link
Collaborator Author

* Remove trailing new line from debug message. It looks awkward with the quote on the next line.

Changed this so that it will print successive lines indented:

image

Other issues addressed and added follow up to list in PR.

async-std = { version = "1.10.0", features = ["attributes", "tokio1"] }
ink_metadata = { version = "3.0.0-rc8", features = ["derive"] }
ink_env = "3.0.0-rc8"
scale-info = { version = "1.0.0", default-features = false, features = ["derive"] }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will probably trigger a dependabot PR for an upgrade to 2.0.0.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll keep it as 1.0.0 for now since that is the same version as ink_metadata rc8 is using.

@ascjones ascjones merged commit 4195197 into master Feb 16, 2022
@ascjones ascjones deleted the aj-contract-call branch February 16, 2022 10:30
@ascjones ascjones mentioned this pull request Feb 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants