Questions tagged [ink]
eDSL to write smart contracts in Rust for blockchains built on the Substrate framework
361
questions
1
vote
1
answer
40
views
What is the significance of default in open brush contracts traits implementation?
I was going through the code of open brush implementation for different tokens, and was confused at a point in PSP22 contract where there is a word written default, as shown below
default fn ...
2
votes
1
answer
49
views
Block_timestamp in contract's e2e_tests
Is it possible to get / set block_timestamp in contract's e2e-tests?
Like ink::env::test::set_block_timestamp.
1
vote
2
answers
55
views
Why does the constructor return `Self`?
From looking at the ink-examples I noticed that the #[ink(constructor)] always returns Self, in stead of emitting an event. Is there a reason behind it?
E.g. why does a simple Ok(()) not do and emit ...
0
votes
0
answers
39
views
trait bounds not met for Client<C, E> in helper function for e2e-tests
I'm using a helper function for my e2e-tests where I want to instantiate a contract:
async fn help_instantiate<C, E>(
mut client: ink_e2e::Client<C, E>,
init_value: i32,
)
I ...
4
votes
1
answer
32
views
ContractNotFound for contract instantiation in e2e-test
I am trying to instantiate multiple contracts in my e2e-test. For some reason it can only find one of my contracts and not the others. Uploading the contract resulted in the same error: ...
4
votes
3
answers
287
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
2
answers
288
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 ...
1
vote
1
answer
22
views
Parity INK contract error when declaring multiple stroage
I have implemented ink contract which use to create token, as shown below, I have two struct with declare
#[ink(storage)], I am getting below error, How to solve it.
#![cfg_attr(not(feature = "...
2
votes
3
answers
66
views
How to sign an extrinsic as a smart contract in the browser?
When working with smart contracts in Contracts UI you sometimes need to call a message as the contract itself.
For example the addOwner message of the Multisig ink! example.
How can I add the contract ...
2
votes
1
answer
114
views
Can I deploy an old ink! v3.x contract on the latest version of substrate/polkadot (pallet-contracts >= polkadot-v0.9.37)?
I have old smart contracts written in ink! v3.x, and I need to update the substrate version (including pallet-contracts) to >= polkadot-v0.9.37. After the update, I'll need to redeploy my smart ...
2
votes
1
answer
116
views
I am trying to push a struct into a Vec in my ink contract but i keep getting rust compiler error
#![cfg_attr(not(feature = "std"), no_std)]
#[ink::contract]
mod crowd_funding {
use ink::storage::Mapping;
#[derive(scale::Decode, scale::Encode)]
#[cfg_attr(
...
0
votes
1
answer
24
views
Auto-upload Contracts To UI OR Pre-Populate Dropzone In Modal For Adding Contracts on Polkadot-JS/apps
We are using a clone of the Polkadot-JS/apps. Our users will need to have several contracts loaded to the UI in order to use the apps. We want our users to be able to add an existing contract to their ...
2
votes
1
answer
58
views
HashMap in ink! smart contract
Around one year ago I have implemented simple DEX in ink!, but today I want to migrate the code to newest ink! and I have an error, in the code I have:
use ink_storage::collections::HashMap;
And this ...
0
votes
1
answer
35
views
Can I make a cross-contract call with constructor (function with "#[ink(constuctor)]" attribute) in ink! contract?
I've been trying to implement cross contract calls in constrcutor but somehow I can't seem to make it right. Is the following code executable?
#[openbrush::contract]
pub mod contract {
#[ink(storage)...
0
votes
2
answers
26
views
How To Alter A Clone of Add.tsx To Add One Specific Contract in Polkadot-JS?
We are trying to modify the Polkadot-JS/apps UI to add an app of our own. We have cloned the Contracts page to make our own page so that we can easily call the contract message functions. Contract, ...
0
votes
1
answer
49
views
Unable to upload Phat Contract build using cargo-contract-2.1.0
I was unable to add contract into https://phat.phala.network/contracts/add.
At the
The contract was built using:
cargo-contract version : cargo-contract-contract 2.1.0-unknown-aarch64-apple-darwin
the ...
2
votes
1
answer
74
views
Failed to instantiate a new WASM module instance: Limit of 32 concurrent instances has been reached
The Problem
I recently switched from polkadot-v0.20.0 to polkadot-v0.37.0 in order to support V4 Ink Smart contracts.
But I am encountering the following error using the npm package @polkadot/api when ...
2
votes
1
answer
47
views
What should the end-user expect after a cross contract call failure
I was attempting to comprehend the workings of cross-contract calling in substrate ink contracts using this particular sample code.
If I provide u64::MAX as the calls_count value, it will result in a ...
2
votes
2
answers
48
views
How to identify that certain event has been emited by a concrete smart contract
Our substrate-based smart contract emits an event, which we're listening for via some RPCs. However, we're unable to confirm if the event is genuinely originating from our smart contract. Therefore, ...
5
votes
1
answer
78
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 ...
1
vote
1
answer
44
views
Error running e2e tests on flipper
I have the substrate-contracts-node running and I run the following command on the flipper contract:
cargo test --features e2e-tests
Results in the following error:
running 4 tests
test flipper::...
3
votes
2
answers
142
views
How to sign a payload using ECDSA in PolkadotJS?
I've followed the cookbook on signing a payload, however this uses sr25519.
I would like to use ECDSA to sign the payload, how can this be done?
I have looked into using the keyring and managed to get ...
3
votes
2
answers
89
views
ensure_root in ink!
For the runtime development the FRAME pallet system provide a function ensure_root that allow us to ensure that the origin o represents the root:
// Only root can call this extrinsic.
ensure_root(...
3
votes
1
answer
119
views
What is refTime and proofSize?
I see refTime and proofSize used frequently (e.g. in polkadot js apps when submitting contract transactions), but I cannot find any docs on them.
So what exactly are they? Specifically relating to ink!...
3
votes
2
answers
44
views
How do i pass a `Vec<u8>` as argument to a contracts function, using the command line(cargo contract)
When using cargo contract to call contracts, in all the examples i've seen, its either been AccountId or boolean or integers(u & i). I need to pass a Vec<u8> to my contract function. I've ...
1
vote
1
answer
72
views
BoundedVec on ink!
BoundedVec is a vector where the length of the queue is always bounded, which is better than Vec for storage because it has a defined a maximum length.
I recommend this StackExchange questions to ...
6
votes
1
answer
119
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 ...
2
votes
1
answer
43
views
What is a storage cell?
Somewhat noob question:
I see the term storage cell talked about a lot on here (mostly regarding Mapping and Lazy), however I cannot find any documentation about it.
What exactly is a storage cell?
...
4
votes
1
answer
47
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 ...
1
vote
1
answer
85
views
how to instantiate contract with initialSupply?
I know this command, instantiate from cli, with initial 1,000,000 supply
cargo contract instantiate --constructor new --args 1_000_000 true --suri //Alice --salt $(date +%s)
To do the same thing with ...
1
vote
2
answers
67
views
How to fix Contract.outOfGas error
I'm trying to call a message on my ink! v3 smart contract using the polkadot-js ContractPromise but I'm getting the error:
system.ExtrinsicFailed::ExtrinsicFailed:: contracts.OutOfGas
This is how I'm ...
2
votes
1
answer
56
views
ContractTrapped, transfer_from CalleeTrapped
DispatchError: ContractTrapped
DispatchError docs: Contract trapped during execution.
Debug message:
panicked at 'encountered error while calling <AccountId as PSP22>::transfer_from: ...
2
votes
1
answer
34
views
How to store IPFS hash on ink! smart contract?
I'm working on an ink! smart contract that will store the IPFS hash for each AccountId. I see that in EVM it's efficient to convert the hash to bytes32. What about in ink!, is Vec<u8> efficient ...
1
vote
1
answer
64
views
How to recover AccountId from ECDSA signature in ink!
In ink! 4.0 ink::env crate, it provides ecdsa_recover function.
It returns compressed public key &[u8, 33] as is explained here.
Assumed that blake2 is used for hashing.
#[ink(message)]
pub fn ...
2
votes
2
answers
71
views
Wasm traps in ink contract but not in a `wasm-pack` test
I have a contract that implements some ZKP verification logic with plonk. The verification logic is contained in some other crate that can be compiled to Wasm, and there are wasm-pack tests like this:
...
2
votes
4
answers
61
views
ink-e2e: Metadata artifacts not generated when importing crate
Context:
I am trying to detach end-to-end tests from my main contract lib.rs. I created a new module in tests_e2e.rs.
I import the module in main contract like so:
lib.rs...vvv
#[cfg(all(test, feature ...
1
vote
1
answer
49
views
Accessing values in cross-crontact calling
I have followed this tutorial to create a cross-contract calling in ink. There are two contracts in the example accumulator and delegator. The accumulator contract has two functions and the delegator ...
0
votes
1
answer
29
views
Retriving the transaction details of a mapping
I have a mapping with 0 to 10. I have values stored in this mapping. If I want to get the information stored on map<5> it gives me the details. Is it possible to get the transaction id and block ...
3
votes
2
answers
87
views
ink! contract upload error
Trying to upload contract to node via cli but occur error.
# Run contract-node
./target/release/substrate-contracts-node --dev --tmp --ws-external --rpc-cors all
# build contract
cargo contract new ...
0
votes
1
answer
69
views
How to design ink! storage to prevent OutOfGas?
I'm trying to write a simple contract but run OutOfGas very quickly. My main storage looks like this:
type Id = u32;
#[ink(storage)]
pub struct Example {
elements: Mapping<Id, ...
0
votes
1
answer
64
views
Error "StorageDepositLimitExhausted" occurs when trying to mint
Error "StorageDepositLimitExhausted" occurs when trying to mint
But I don't know why this error happens
The code is here
#![cfg_attr(not(feature = "std"), no_std)]
#![feature(...
1
vote
1
answer
57
views
Create multiple contracts in one ink
I want to create two contracts in one ink file. The second contract use functions and mapping of the first contract. Here is an example
#[ink::contract]
mod contract_1 {
pub struct Struct1 {}
#...
0
votes
2
answers
72
views
What is the cause of this contracts.ContractTrapped error?
I have had two contracts (A, B), where contract a calls a function on contract b, when contract a is deployed. This works fine up to a certain point where I receive a contracts.ContractTrapped error (...
2
votes
1
answer
40
views
Is it possible to prove that an account deployed contract A from within contract B without the account being stored in contract A?
Account A deploys Contract A. Account A then calls Contract B function register, passing the address of Contract A. Is it possible to prove that Account A deployed Contract A from within the register ...
1
vote
1
answer
58
views
How to handle TX error on dapp frontend?
Testing contract on polkadotjs, we can easily see user defined or error given by runtime like this:
But working with same contract in frontend I am not able to handle error response in frontend. ...
0
votes
1
answer
44
views
Calling ink! contracts not working
I have been trying to call the flipper ink! contract from polkadot.js contracts section I keep getting this error.
I've build the smart contract using cargo +nightly contract build and am using ink! ...
0
votes
1
answer
81
views
How to Call a Smart Contract on the Backend
What is the best way to call a contract (based on the Substrate Blokchain) on the backend side from the code? I know there is Polkadot.js but it's rather a frontend focused tool, and there is also ...
0
votes
1
answer
37
views
how to iterate a mapping with values as a struct
I have a mapping that has values and I would like to iterate the map and display the results that satisfy the condition and return the results as the array. The function looks like this
fn iterate_map(...
1
vote
1
answer
51
views
how to treat u256 in ink?
I want to use U256 in ink! but I've got some a error although I imported primitive_types/std....
how can I solve it?
use primitive_types::U256;
pub mod liquidity_num {
pub const MIN_TICK: i32 = -...
0
votes
1
answer
52
views
ENOENT: no such file or directory on compile and deploy swanky contract
This issue display when I clone the swanky project from GH and try to compile.
swanky contract compile {project_name}
I try to ignore the issue which display while compiling and try to deploy and got ...