3

When going through this tutorial for adding contracts to the default node template, adding pallets-contracts-rpc, the 4th recommended crate to install, I receive various errors. Things compile fine when only the first 3 crates are installed.

[package]
name = "node-template-runtime"
version = "4.0.0-dev"
description = "A fresh FRAME-based Substrate runtime, ready for hacking."
authors = ["Substrate DevHub <https://github.com/substrate-developer-hub>"]
homepage = "https://substrate.io/"
edition = "2021"
license = "Unlicense"
publish = false
repository = "https://github.com/substrate-developer-hub/substrate-node-template/"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }

pallet-aura = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24" }
pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24" }
frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24" }
pallet-grandpa = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24" }
pallet-randomness-collective-flip = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24" }
pallet-sudo = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24" }
frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24" }
frame-try-runtime = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24", optional = true }
pallet-timestamp = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24" }
pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24" }
frame-executive = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24" }
sp-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24" }
sp-block-builder = {  version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24"}
sp-consensus-aura = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24" }
sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24" }
sp-inherents = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24"}
sp-offchain = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24" }
sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24" }
sp-session = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24" }
sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24" }
sp-transaction-pool = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24" }
sp-version = { version = "5.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24" }

# Used for the node template's RPCs
frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24" }
pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24" }

# Used for runtime benchmarking
frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24", optional = true }
frame-system-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24", optional = true }
hex-literal = { version = "0.3.4", optional = true }

pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24" }
pallet-contracts-primitives = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24" }
pallet-contracts-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24" }
pallet-contracts-rpc = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24" }

# Local Dependencies
pallet-template = { version = "4.0.0-dev", default-features = false, path = "../pallets/template" }

[build-dependencies]
substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.24" }

[features]
default = ["std"]
std = [
    "codec/std",
    "scale-info/std",
    "frame-executive/std",
    "frame-support/std",
    "frame-system-rpc-runtime-api/std",
    "frame-system/std",
    "pallet-aura/std",
    "pallet-balances/std",
    "pallet-grandpa/std",
    "pallet-randomness-collective-flip/std",
    "pallet-sudo/std",
    "pallet-template/std",
    "pallet-timestamp/std",
    "pallet-transaction-payment-rpc-runtime-api/std",
    "pallet-transaction-payment/std",
    "pallet-contracts/std",
    "pallet-contracts-rpc-runtime-api/std",
    "sp-api/std",
    "sp-block-builder/std",
    "sp-consensus-aura/std",
    "sp-core/std",
    "sp-inherents/std",
    "sp-offchain/std",
    "sp-runtime/std",
    "sp-session/std",
    "sp-std/std",
    "sp-transaction-pool/std",
    "sp-version/std",
]
runtime-benchmarks = [
    "frame-benchmarking/runtime-benchmarks",
    "frame-support/runtime-benchmarks",
    "frame-system-benchmarking",
    "frame-system/runtime-benchmarks",
    "hex-literal",
    "pallet-balances/runtime-benchmarks",
    "pallet-grandpa/runtime-benchmarks",
    "pallet-template/runtime-benchmarks",
    "pallet-timestamp/runtime-benchmarks",
    "sp-runtime/runtime-benchmarks",
]
try-runtime = [
    "frame-executive/try-runtime",
    "frame-try-runtime",
    "frame-system/try-runtime",
    "pallet-aura/try-runtime",
    "pallet-balances/try-runtime",
    "pallet-grandpa/try-runtime",
    "pallet-randomness-collective-flip/try-runtime",
    "pallet-sudo/try-runtime",
    "pallet-template/try-runtime",
    "pallet-timestamp/try-runtime",
    "pallet-transaction-payment/try-runtime",
]

...
  error[E0308]: mismatched types
      --> /Users/g/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.4/src/socket.rs:1777:25
       |
  1777 | from!(net::TcpListener, Socket);
       |                         ^^^^^^ expected struct `Socket`, found `()`
       |
      ::: /Users/g/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.4/src/lib.rs:104:16
       |
  104  |             fn from(socket: $from) -> $for {
       |                ---- implicitly returns `()` as its body has no tail or `return` expression

  error[E0308]: mismatched types
      --> /Users/g/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.4/src/socket.rs:1778:23
       |
  1778 | from!(net::UdpSocket, Socket);
       |                       ^^^^^^ expected struct `Socket`, found `()`
       |
      ::: /Users/g/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.4/src/lib.rs:104:16
       |
  104  |             fn from(socket: $from) -> $for {
       |                ---- implicitly returns `()` as its body has no tail or `return` expression

  error[E0308]: mismatched types
      --> /Users/g/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.4/src/socket.rs:1779:15
       |
  1779 | from!(Socket, net::TcpStream);
       |               ^^^^^^^^^^^^^^ expected struct `TcpStream`, found `()`
       |
      ::: /Users/g/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.4/src/lib.rs:104:16
       |
  104  |             fn from(socket: $from) -> $for {
       |                ---- implicitly returns `()` as its body has no tail or `return` expression

  error[E0308]: mismatched types
      --> /Users/g/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.4/src/socket.rs:1780:15
       |
  1780 | from!(Socket, net::TcpListener);
       |               ^^^^^^^^^^^^^^^^ expected struct `TcpListener`, found `()`
       |
      ::: /Users/g/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.4/src/lib.rs:104:16
       |
  104  |             fn from(socket: $from) -> $for {
       |                ---- implicitly returns `()` as its body has no tail or `return` expression

  error[E0308]: mismatched types
      --> /Users/g/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.4/src/socket.rs:1781:15
       |
  1781 | from!(Socket, net::UdpSocket);
       |               ^^^^^^^^^^^^^^ expected struct `UdpSocket`, found `()`
       |
      ::: /Users/g/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.4/src/lib.rs:104:16
       |
  104  |             fn from(socket: $from) -> $for {
       |                ---- implicitly returns `()` as its body has no tail or `return` expression

...

It seems on the contracts node template that crate is not installed. https://github.com/paritytech/substrate-contracts-node/blob/main/runtime/Cargo.toml

3
  • 3
    Perhaps mismatched versions of substrate used? Try from scratch, ensure your lock file has only one commit used for substrate deps
    – Nuke
    Commented Jun 21, 2022 at 0:57
  • 1
    Did a fresh clone of node template, ensured all are on branch polkadot-v0.9.24, added contracts and contracts-rpc-runtime-api to std, and using cargo check to validate. Still seeing those errors only when adding pallet-contracts-rpc. I've update the Cargo.toml above Commented Jun 21, 2022 at 15:51
  • Were you able to solve this? I'm having the exact same error Commented Jul 7, 2022 at 14:20

1 Answer 1

1

It looks like you're adding the pallet-contracts-rpc dependency to the runtime (runtime/Cargo.toml). It should only be added to the node (node/Cargo.toml) though.

The reason is that everything under runtime/ will be run in an isolated no_std sandbox mode in WebAssembly, whereas the RPC endpoints are very much exposed to the outside networking world.

There is some glue between sandbox and node (you can think of the node as a client running the runtime within). This glue code is the pallet-contracts-rpc-runtime-api.

The tutorial has been updated by now (the link from the top post also no longer works). I'm not sure what the tutorial was referring to before, but the current one under https://docs.substrate.io/tutorials/work-with-pallets/contracts-pallet/ contains the correct instructions.

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.