2

I have tried following instructions from:

https://rustrepo.com/repo/paritytech-substrate-contracts-node

and

https://ink.substrate.io/faq/#how-do-i-print-something-to-the-console-from-the-runtime

My process:

1 - Add debug statements to the contract code:

#[ink(constructor)]
pub fn new() -> Self {
  ink_env::debug_println!("created new instance at {}", Self::env().block_number());
  Self {}
}

#[ink(message)]
pub fn sayhello(&self) {
  ink_env::debug_println!("Hello");
}

2 - build: cargo +nightly contract build.

OUTPUT:

Original wasm size: 32.7K, Optimized: 11.1K

The contract was built in DEBUG mode.

Your contract artifacts are ready. You can find them in:
/home/IamDeveloper/MySoftwareProjects/blockchain/rust/rust-substrate-blockchain-projects/my-first-substrate-projects/my-first-project-prep-lesson/my-first-smart-contracts/helloworld/target/ink

  - helloworld.contract (code + metadata)
  - helloworld.wasm (the contract's code)
  - metadata.json (the contract's metadata)

3 - In another terminal, run the node:

substrate-contracts-node --dev -lerror,runtime::contracts=debug

4 - In the original terminal, upload:

cargo contract upload --suri //Alice

5 - Get the code hash:

code_hash=0xfd548906549af08bbb8bdd436f46b457d2b6ea9f8b6610e9515b3c4e7fe22d9c

6 - Instantiate:

cargo contract instantiate \
  --gas 500000000000 \
  --constructor new \
  --suri //Alice \
  --code-hash $code_hash

7 - Get the Contract:

Contract=5E4V3mvaf2nYKLRJJMNhc6TXrM5GxNwsga4hESRPquCXEyu1

8 - Call:

cargo contract call \
  --gas 500000000000 \
  --message sayhello \
  --suri //Alice \
  --contract $Contract

RESULT: No output at all from the terminal running the node.

1 Answer 1

1

I have the following ink! message:

#[ink(message)]
pub fn say_hello(&self) {
    ink_env::debug_println!("Hello");
}

I run my node like this:

./target/release/substrate-contracts-node --dev -lerror,runtime::contracts=debug

If I call like this:

cargo contract call \
  --gas 500000000000 \
  --message say_hello \
  --suri //Alice \
  --contract 5HJSXhYLExB5KYCMXa95mKEUX4UXXsp8Up9rBLzR57PPwtkq

The following appears in my node logs:

2022-08-02 13:07:28.410 DEBUG tokio-runtime-worker runtime::contracts: Execution finished with debug buffer: Hello

Make sure your contract exists.

You should see it in https://polkadot.js.org/apps/#/contracts

Also, try deleting your contract and re-deploying. You may have an old contract there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.