Questions tagged [ink]
eDSL to write smart contracts in Rust for blockchains built on the Substrate framework
471
questions
22
votes
3
answers
696
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 ...
13
votes
2
answers
361
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/...
11
votes
3
answers
557
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, ...
10
votes
4
answers
1k
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 ...
10
votes
2
answers
236
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 ...
8
votes
3
answers
214
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 ...
8
votes
4
answers
1k
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`). ...
8
votes
1
answer
297
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. ...
7
votes
2
answers
340
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?
7
votes
1
answer
128
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 ...
7
votes
1
answer
125
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 ...
6
votes
1
answer
344
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 ...
6
votes
1
answer
236
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! ...
6
votes
2
answers
192
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 ...
6
votes
1
answer
154
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 ...
6
votes
2
answers
204
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?
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 ...
6
votes
1
answer
52
views
What does error `TooManyTopics` mean?
While trying out my contract I get the error: TooManyTopics, what is wrong?
6
votes
1
answer
56
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 ...
6
votes
0
answers
67
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 ...
5
votes
2
answers
79
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 ...
5
votes
1
answer
129
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....
5
votes
1
answer
105
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 ...
5
votes
2
answers
247
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 ...
5
votes
1
answer
97
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 ...
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 ...
5
votes
1
answer
55
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 ...
5
votes
2
answers
103
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::...
5
votes
1
answer
162
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?
5
votes
2
answers
151
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-...
5
votes
1
answer
119
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 ...
5
votes
1
answer
112
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 ...
5
votes
1
answer
64
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 ...
5
votes
1
answer
30
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 ...
5
votes
1
answer
117
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 ...
5
votes
2
answers
146
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 ...
5
votes
1
answer
96
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 ...
5
votes
1
answer
54
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&...
5
votes
1
answer
99
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.
5
votes
0
answers
29
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 ...
5
votes
1
answer
50
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 ...
5
votes
2
answers
86
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",
&...
4
votes
3
answers
240
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.
4
votes
2
answers
125
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 ...
4
votes
2
answers
553
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 ...
4
votes
2
answers
363
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 ...
4
votes
5
answers
307
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 ...
4
votes
3
answers
336
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 ...
4
votes
1
answer
200
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 ...
4
votes
1
answer
288
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 ...