Questions tagged [ink]

eDSL to write smart contracts in Rust for blockchains built on the Substrate framework

Filter by
Sorted by
Tagged with
22 votes
3 answers
750 views

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

What are the differences between developing a Substrate FRAME Pallet and a Substrate Smart Contract (for example with the ink! language)? What are some examples of applications which are best written ...
Shawn Tabrizi's user avatar
  • 16k
13 votes
2 answers
375 views

How to test cross-contract Ink! contracts

In the latest master of Ink! examples there is only one main contract, delegator, for understanding cross-contract calls. Unfortunately, there are no tests either for this system. https://github.com/...
Drew Stone's user avatar
  • 1,194
11 votes
3 answers
640 views

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

I'm a newbie with rust and substrate. I'm currently trying to build a PSP34 compatible smart contract (NFT) for documents. In this contract, I'd like to have the following structure: #[derive(Default, ...
edmassarani's user avatar
10 votes
4 answers
2k views

ERROR: Loading of original wasm failed

I having some trouble running the Flipper example from the Ink! webpage. The cargo contract build outputs the following error log: ERROR: Loading of original wasm failed Caused by: 0: Loading of ...
statisticalanomaly's user avatar
10 votes
2 answers
247 views

Calling the function of an other contract in Solidity

Do you know if is it possible to call the function of an other contract in Solidity used in Substrate based chain and compiled with solang ? At first glance it seems impossible but I doubt it. As a ...
Dream's user avatar
  • 101
8 votes
3 answers
230 views

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

I came across the ink_storage::Mapping data structure. The official doc seems to explain that how to use it but not why it's needed. It seems more complicated to initialize and work with than the maps ...
Kar Keung Christopher Fok's user avatar
8 votes
4 answers
2k views

How to resolve duplicate lang item error?

I couldn't compile ink_env when doing cargo contract build. Tried cargo update by referencing this other [post] (error: duplicate lang item in crate `std` (which `arrayvec` depends on): `panic_impl`). ...
Kar Keung Christopher Fok's user avatar
8 votes
1 answer
387 views

How to estimate gas for ink contracts transactions for Weights V2?

For ink contracts with weight v2 it requires refTime and proofSize. For this we are first querying(dry run) the transaction method, getting gasRequired from query result and sending it to transaction. ...
Nikhil Ranjan's user avatar
8 votes
0 answers
90 views

What are the size limits of contract storage in ink?

Whilst reading the docs for ink I came across this warning: CAUTION If any type exhibiting Packed layout gets large enough (an ever-growing Vec might be a prime candidate for this), it will break ...
goastler's user avatar
  • 569
7 votes
2 answers
405 views

How to decode ink smart contract call and event data?

I want to decode the contract call data and event data saved in a block. How can I do that?
Minh Mốc's user avatar
7 votes
1 answer
139 views

Is the WASM blob created from ink! contract always deterministic

The contract's source code is provided during the contract verification on a block explorer (or some other source verifier). The block explorer needs to compile that source and verify if the generated ...
Maario's user avatar
  • 659
7 votes
1 answer
143 views

How to properly handle cross contract call errors

In the scenario where a cross-contract call from contract A to contract B fails, how can we manage the resulting errors? Specifically, if the call from A to B is unsuccessful, what are the options for ...
Alejandro Martínez's user avatar
6 votes
1 answer
412 views

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

From what I understand from the docs, every contract gets its own AccountId. But in the contract-transfer tests, I'm getting the same AccountId from both accounts.alice and contract_id(). I modified ...
Kanishka's user avatar
  • 465
6 votes
1 answer
271 views

How to verify a signature in ink! contracts

I'm trying to create a contract that verifies the signature in a contract function. I wasn't able to find anything in the examples or in the docs. Is it possible to send a signature to an ink! ...
Kanishka's user avatar
  • 465
6 votes
2 answers
202 views

How do I test a chain extension used in the runtime?

I am aware of this example that shows how to create a mock chain extension and test that. However, I do not know how to test the chain extension that is used by the runtime and calling functions from ...
ExplodingJay's user avatar
6 votes
1 answer
175 views

How to validate for Address Zero in Ink1 4.0

Previously in Ink! 3, in a function which is accepting AccountId as a parameter, One can validate that the address passed is not AddressZero by using .is_zero() on the parameter variable name but I ...
Developer Uche's user avatar
6 votes
2 answers
230 views

How to iterate over Mapping<K,V>?

I have a very basic question - ink! now has a Mapping struct for key-value pairs. It seems it does not implement the Iterator trait?
fbielejec's user avatar
  • 331
6 votes
1 answer
57 views

ink! tutorial: contracts-node fails to compile

sorry if this is not the right forum, but here goes: cargo install contracts-node --git https://github.com/paritytech/substrate-contracts-node.git --tag v0.10.0 --force --locked This fails with the ...
jonathan_belolo's user avatar
6 votes
1 answer
58 views

What does error `TooManyTopics` mean?

While trying out my contract I get the error: TooManyTopics, what is wrong?
Daan van der Plas's user avatar
6 votes
1 answer
59 views

Are Vec<T> stored with unused space in ink?

I'm using a Vec<T> in ink!. When allocating elements to the vec, the underlying array may be resized to provide a constant amortised push complexity of O(1). This means that sometimes the vec ...
goastler's user avatar
  • 569
5 votes
2 answers
96 views

Trying to implement U256 in rust ink! 4.0

I've implemented use primitive_types::U256 and now I'm trying to return a U256 int as a result from one of my functions, but I'm getting the following error: the trait TypeInfo is not implemented for ...
yonatan hornstein's user avatar
5 votes
1 answer
130 views

How to upload contract using a custom made frontend?

I am making a new UI for substrate based blockchain, and found the code here to upload a Smart Contract. The code allows you to either upload metadata.json && cont.wasm files or a cont....
Divyam Garg's user avatar
5 votes
2 answers
272 views

ink design: Why are chain extensions explicitly defined and why do they use function ids instead of the runtime pallet and function naming?

I'm looking at ink! contracts and chain extensions. Two questions that came up that I did not find an answer by browsing the docs. Both questions are related to the design of integrating ink! with ...
Dominik Harz's user avatar
5 votes
1 answer
116 views

Efficient debugging method with ink!

Problem I always use the following method to debug ink! However, that method is not very efficient when implementing complex contracts. Furthermore, there is a demerit that many debug statements will ...
s.Takahashi's user avatar
5 votes
1 answer
110 views

Why is the AccountId of a contract always 1 when unit testing?

I've been building unit tests in ink and have come across a strange issue. If I instantiate a contract multiple times, the account id is always the same. I thought the account id is the address of the ...
goastler's user avatar
  • 569
5 votes
1 answer
56 views

What governs Treasury funds out?

My question is: What governs access to treasury funds? I’m assuming it requires an ink contract that governs who is able to invoke funds transfers out of the treasury and which conditions apply. Is ...
Json's user avatar
  • 53
5 votes
1 answer
57 views

using String in ink version 4

so I am migrating my contract from version 3 to 4 my goal is to use the open brush as well but we can not use the open brush in ink version 4 because it still needs the nightly features and Ink v4 ...
Rahul navgire's user avatar
5 votes
2 answers
143 views

Problem with Vec using ink

I'm trying to make some changes to the Flipper contract, trying to use a vector like the documentation say's it should be imported: #[ink::contract] pub mod flipper_plus { use ink::storage::...
Pierina Ponce's user avatar
5 votes
1 answer
196 views

How to call runtime functions from a contract

A chain_extension is one way to call into the runtime from a smart contract on the contracts pallet. What other methods exist, and why might you use them instead of the extension pattern?
Bernardo Rodrigues's user avatar
5 votes
2 answers
192 views

"ERROR: Loading of original wasm failed" after upgrading rustup

I'm getting the following error when compiling a rust ink! 4.0; ERROR: Loading of original wasm failed It's started happening to me after I rustup update and now my rustc versions are: stable-...
yonatan hornstein's user avatar
5 votes
1 answer
132 views

Best way to handle Solidity's `uint256` in ink!

I have been working on creating a guide to port Solidity smart contracts to ink! smart contracts. I was hoping for some input on how to best handle Solidity's uint256 in ink!. Solidity is optimized ...
Peter - R0GUE's user avatar
5 votes
1 answer
113 views

How to receive input for mocked ink_env::test::ChainExtension

I'm trying to write an off-chain test for an ink! smart-contract that uses chain extensions. The example showing how to mock an extension for tests is never using the supplied _input argument. The ...
ebma's user avatar
  • 53
5 votes
1 answer
77 views

How do I upgrade an ink contract with storage changes?

Let's say I have a simple/contrived ink contract: #[ink(storage) pub struct MyContract { a: u8, b: u8, } Now let's say it's in production and a == 1 and b == 2. I've done some work and ...
goastler's user avatar
  • 569
5 votes
1 answer
33 views

The package `` depends on `ink_env`, with features: `ink-experimental-engine` but `ink_env` does not have these features

I want to write tests and found the question that potentially soles my problem, but made exactly all what is recommended but still have the same issue. I have added on top of my module with tests ...
Tomasz Waszczyk's user avatar
5 votes
1 answer
135 views

How to identify received contract event?

My contract emits several [ink(event)] events. My application subscribes to the events and receives Contracts_ContractEmitted data (from centrifuge go-substrate-rpc-client). How may I understand which ...
Denis Glotov's user avatar
5 votes
2 answers
152 views

Is circular call between multi contracts possible?

Background I have two contracts A and B, I can do cross-contract call from A to B, or from B to A. But it failed when I try to do cross-contract call like this: A -> B -> A. Test code I ...
george huang's user avatar
5 votes
1 answer
106 views

Cross Contract e2e test type annotation needed for events

I have two ink! contracts and one of those contracts is making calls to the other one using a CallBuilder. I want to test that with e2e ink! tests and I am running into a problem. For reference, one ...
Szegoo's user avatar
  • 657
5 votes
1 answer
61 views

No callee has been set

I write some test for ink! smart contract, my code has these three lines: // Set the contract as callee and Bob as caller. let _contract = ink_env::account_id::<ink_env::DefaultEnvironment&...
Tomasz Waszczyk's user avatar
5 votes
1 answer
103 views

How to benchmark a chain extension?

I would like to know the recommended way to benchmark a chain extension, and then how to charge the calculated weight. According to this document, we need to write benchmarks.
ExplodingJay's user avatar
5 votes
0 answers
37 views

Cross-contract call failed with TransferFailed

After instantiating a contract using the CreateBuilder as shown here. If I then try to call the contract using CallBuilder as shown here and use #[ink(message, payable)] in the callee message of the ...
Luke Schoen's user avatar
  • 2,322
5 votes
1 answer
53 views

Fixed size array in ink smart contract storage

How can I have a fixed size array in my ink smart contract storage? E.g. // Contract storage #[ink(storage)] pub struct MyContract { myArray: [u8; 64] } I get "the trait ...
goastler's user avatar
  • 569
5 votes
2 answers
89 views

Why would a cross contract call be giving `NotCallable`?

I'm hitting an error when trying to do a cross contract call with two contracts running on substrate branch monthly-2022-03 and compiled with "language": "ink! 3.0.0-rc8", &...
forgetso's user avatar
  • 1,492
4 votes
3 answers
243 views

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

I'd like to know if there's a chain that smart contract is being in mainnet use of it.
Mehdi Raash's user avatar
4 votes
2 answers
134 views

Correct way to use dynamic sized types in chain extension

I'm writing chain extensions for my pallets and I have a few functions that require dynamic sized types, for example Vec<u8> for metadata and Vec<u64> for a list of asset ids. The way I am ...
Gabe's user avatar
  • 115
4 votes
2 answers
565 views

Factors affecting storage field key generation in ink!

I've got a couple of questions regarding the storage fields' key generation using AutoKey in the context of upgradable contracts and partial ManualKey usage. Does the use of ManualKey in some storage ...
Nimish Agrawal's user avatar
4 votes
2 answers
453 views

Generating random numbers in ink!

I've been trying to use most common let mut rng = rand::thread_rng(); let winner_pos = rng.gen_range(0..10); way to get a random number and use it in one of the contract's messages. But it throws a ...
CREESTL's user avatar
  • 474
4 votes
5 answers
316 views

Cargo contract 3.0.1

Ink! 3.1.0 has been released today, and it seems that it has been automatically embed/used in the cargo-contract command. The result is that newly compiled contract are no more compatible with node ...
LaurentTrk's user avatar
4 votes
3 answers
352 views

How to calculate square root of a number in ink! smart contract?

In the classic flipper ink! sc example I tried within a function let dist2: f32 = f32::sqrt(4.0); and got the error " function or associated item not found in f32 " Bearing in mind this ...
Sokrates's user avatar
  • 421
4 votes
1 answer
209 views

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

I am working on chain extension to call rmrk pallet methods. One of the methods needs a BoundedVec that I need to pass via ink smart contract. What data type can I use to do this on smart contract ...
Ankan's user avatar
  • 325
4 votes
1 answer
354 views

How to return the whole Mapping from a contract method?

I'm a newbie in Rust, Substrate, and blockchain development. I'm developing an ink! smart contract that store a list of items. Since the storage version of Vec is not available yet, I use a Mapping to ...
Promlert Lovichit's user avatar

1
2 3 4 5
10