Skip to main content
26 votes
Accepted

When should I build a Substrate FRAME Pallet versus a Smart Contract?

Substrate Pallets and Substrate Smart Contracts are two different approaches to building "decentralized applications" using the Substrate framework. Smart Contracts A traditional smart ...
Shawn Tabrizi's user avatar
  • 16.1k
14 votes
Accepted

What's the need for ink_storage::Mapping instead of the maps defined by Rust's standard library?

I assume that with "standard mapping" you mean the maps defined in Rust's standard library: HashMap and BTreeMap. The reason for the existence of ink_storage::Mapping is that it works ...
Alexander Theißen's user avatar
13 votes

Calling the function of an other contract in Solidity

I was able to reproduce your problem. I even stripped down your contracts even more and was able to isolate the cross contract call as root of the problem. I also compiled with the latest solang ...
Alexander Theißen's user avatar
13 votes

Are there blockchains based on substrates that use smart contracts and are on mainnet?

Thank you for your question. This is Sota, founder of Astar Network. Astar is a multichain smart contract hub on Polakdot supporting WASM and EVM. Polkadot doesn't support smart contracts by design ...
Sota Watanabe's user avatar
12 votes
Accepted

How to have a mapping in a custom structure inside an ink! contract?

In your original question the errors have to do with you trying to derive traits on your struct which Mapping doesn't implement. For example, the #[derive(Clone)] macro tries to call clone() on every ...
HCastano's user avatar
  • 1,071
11 votes
Accepted

ERROR: Loading of original wasm failed

Solved! This was caused by the nightly toolchain. Switching to the stable toolchain solved this issue. Edit: As pointed out by Shunsuke, this is specific to the 1.70.0 nightly build. 1.68.0 version ...
statisticalanomaly's user avatar
10 votes

What's the need for ink_storage::Mapping instead of the maps defined by Rust's standard library?

The first question, what is standard Mapping?=) I will describe differences for standard hashmap from the Rust - ink_prelude::collections::HashMap. Hope it answers your question. ink_prelude::...
Green Baneling's user avatar
10 votes
Accepted

What is refTime and proofSize?

For ink!, the term Gas refers to the resources used by a contract call. It's important for smart contracts that the caller has to pay for any utilized resource. Those resources can be either storage ...
cmichi's user avatar
  • 2,800
9 votes

How to test cross-contract Ink! contracts

I'm posting a link to the discussion on GitHub: https://github.com/paritytech/ink/issues/1125. AFAIK there is currently only the the possibility to do this with the redspot tool mentioned in the issue....
cmichi's user avatar
  • 2,800
9 votes
Accepted

Is the WASM blob created from ink! contract always deterministic

Currently we don't persist the information necessary to have a deterministic build. There is this GitHub issue for it: https://github.com/paritytech/cargo-contract/issues/525. The underlying issue is ...
cmichi's user avatar
  • 2,800
8 votes

How to decode ink smart contract call and event data?

Having this data in hex format, you can decode it using cargo-contract command line utility simply like this (run from the contract src folder): cargo contract decode -d <data_hex_string> -t ...
Alexander Gryaznov's user avatar
8 votes

How to resolve duplicate lang item error?

There are two primary troubleshooting steps based off comments and messages surrounding the problem. Ensure all your dependencies are set to the same branch and tag, mismatches are known to be a ...
Kittywhiskers Van Gogh's user avatar
8 votes
Accepted

How to verify a signature in ink! contracts

At the moment contract-pallet allows you only to verify ECDSA signatures. In ink! you can use ink_env::ecdsa_recover to do that.
Green Baneling's user avatar
8 votes
Accepted

How to get an ink! contract's AccountId in unit tests?

The testing Engine is still limited in some capabilities: It is correct that a Smart Contract obtains its own AccountId, but I doubt that this is currently reflected by the testing Engine, since it ...
Achim's user avatar
  • 575
8 votes
Accepted

Panic in Ink! Smart Contracts

panic! reverts the state but it also ends the execution of the current contract call. If your method was called by another contract, that contract will receive a CalleeTrapped error instead of the ...
Green Baneling's user avatar
8 votes
Accepted

How to upload contract using a custom made frontend?

The code allows you to either upload metadata.json && cont.wasm files or a cont.contract file. The difference between the files is as follows: hello-world.wasm Just the WebAssembly bytecode. ...
cmichi's user avatar
  • 2,800
8 votes
Accepted

error[E0158] when testing default contract from flipper

cargo-contract latest release currently is v1.5.0 which was released on 15th August 2022. So I used rust nightly build of that day and it worked. I have ran the following commands and I am able to ...
Rahul Soshte's user avatar
8 votes
Accepted

Is there any way to verify ink smart contract

Currently, it's not yet possible. It will be available the moment ink!4.0 is released. Astar is talking with Subscan to make this available when the latest version is ready. To give you a more clear ...
Maarten Henskens's user avatar
7 votes
Accepted

How can I use a specific version of ink?

You can set a fixed dependency version in your Cargo.toml by using = in front of the version number. For example, like this: ink_primitives = { version = "=3.0.0-rc9", default-features = ...
cmichi's user avatar
  • 2,800
7 votes
Accepted

Rust ink. Division wont return a number with float point

You cannot use floating point maths in ink!. If you do something like 10/7 then you will get 1 as a result (rounded from 1.42857142857). It looks like you're calculating 1e12/200e12 which is 0.005 and ...
forgetso's user avatar
  • 1,514
7 votes
Accepted

How to return the whole Mapping from a contract method?

Mapping is a memory efficient storage type that doesn't hold an index of what's inside it. It is simply a key-value store. You will need to store a list of keys that contain values inside the Mapping. ...
forgetso's user avatar
  • 1,514
7 votes
Accepted

Correct way to use dynamic sized types in chain extension

In order to read memory from a contract you should check out the different functions on the Environment type. As Green Baneling already pointed out correctly you should use SCALE in order to encode ...
Alexander Theißen's user avatar
7 votes
Accepted

How to get AccountId from compressed public key in an ink! contract?

A compressed public key can be represented by the ECDSAPublicKey struct from the eth_compatibility crate from ink. Try to create an ECDSAPublicKey struct from your uncompressed public key and then ...
Achim's user avatar
  • 575
7 votes

How to iterate over Mapping<K,V>?

There is no way to iterate over a Mapping from a contract. We intent to implement this functionality soon. For more information check out this issue: https://github.com/paritytech/substrate/issues/...
Alexander Theißen's user avatar
7 votes
Accepted

Ink cannot derive SpreadLayout and SpreadAllocate for simple struct and enum

SpreadAllocate can't be derived for the enums(issue), so you should implement it manually. You are deriving SpreadLayout wrong=) #[cfg_attr(feature = "std", derive(...)] means - derive it ...
Green Baneling's user avatar
7 votes
Accepted

Why the function names and parameter names are changed when I use in polkadot api?

Polkadot.js transforms contract message names to camelCase for consistency across its packages and alignment with JavaScript common practice. https://polkadot.js.org/docs/api-contract/FAQ#why-is-there-...
Andreea Eftene's user avatar
7 votes
Accepted

How can I pass a Vec<u8> via chain extension to pallet?

You can only use read_as() for types whose size is known at compile time (thus the requirement that types implement MaxEncodedLen). If you don't know the size ahead of time, like in the case of a Vec, ...
HCastano's user avatar
  • 1,071
7 votes

How to validate for Address Zero in Ink1 4.0

An easy method you can use to get the AddressZero is this: fn zero_address() -> AccountId { [0u8; 32].into() } And compare it to another address, see an example here: ensure!(to != ...
Alex Bean's user avatar
  • 5,747
7 votes
Accepted

How to properly handle cross contract call errors

All the code I mention here is available in this repo. There are three types of errors that you need to may want to handle when doing cross-contract calls Contract Errors: defined by the smart ...
HCastano's user avatar
  • 1,071
6 votes
Accepted

ink! tutorial: contracts-node fails to compile

rustup default nightly, and then rerun. It's accessing nightly features. I can confirm that it builds using cargo 1.61.0-nightly (65c8266 2022-03-09) on linux.
Squirrel's user avatar
  • 3,849

Only top scored, non community-wiki answers of a minimum length are eligible