Skip to main content

Questions tagged [ink]

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

Filter by
Sorted by
Tagged with
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
3 votes
1 answer
451 views

error[E0158] when testing default contract from flipper

https://docs.substrate.io/tutorials/smart-contracts/prepare-your-first-contract/ Hi, I'm working on the above tutorial and after running the cargo +nightly test command, I see the following error. ...
kenta_desu's user avatar
11 votes
3 answers
661 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
4 votes
1 answer
284 views

How does cross contract calling with openbrush work exactly?

The title of the question is a bit open ended, but I am trying to make cross contract calling work right now and realised, that there is a lot of open question on how it exactly works and how the ...
rajohs's user avatar
  • 491
4 votes
1 answer
273 views

What is the best way to make a cross contract call on Ink!

I found 2 ways to make cross contract calls on ink!. The first is in this link here where another contract is called directly, The second is in this link here where a reference(ref) is being used. I ...
dharjeezy's user avatar
  • 419
13 votes
2 answers
377 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
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
5 votes
1 answer
201 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
3 votes
1 answer
337 views

Ink cannot derive SpreadLayout and SpreadAllocate for simple struct and enum

When developing Ink! smart contracts I found that SpreadLayout and SpreadAllocate cannot be derived for simple structs or enums that are members variables of the contract and I have to implement the ...
mastro's user avatar
  • 217
2 votes
2 answers
206 views

Contract storage needs nested orderbooks; best practice way to structure dapp?

For my dapp I need storage which can reference a mutable amount of events, all of which have their own orderbook. Expanded, it looks something like this: CoreStorage { coin_storage: CoinStore, //...
bingo_boingo_bungus's user avatar
22 votes
3 answers
779 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
  • 16.1k
5 votes
1 answer
139 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
4 votes
3 answers
353 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
2 answers
363 views

How to sign a message using ECDSA key pairs in Polkadot.js so it can be verified in the ink! contract

I want to build an ink! contract where some functions need to verify messages signed by the caller. In ink! contract there is a helper function named ink_env::ecdsa_recover(), which seems helpful in ...
Soptq's user avatar
  • 41
4 votes
1 answer
375 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
4 votes
2 answers
137 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
2 votes
1 answer
118 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 ...
Alex Bean's user avatar
  • 5,757
0 votes
1 answer
88 views

Vec<AccountId> breaks compilation of ink! contract

In my contract I want to store addresses of all users who called a specific function of the contract. For that purpose I use #[ink(storage)] #[derive(SpreadAllocate)] pub struct Postbox { ...
CREESTL's user avatar
  • 484
0 votes
3 answers
248 views

Parsing JSON in ink based Smart Contracts

Currently I am developing a Fat Contract (Native to Phala Network) that also supports Ink Based Smart Contracts to be written within the Fat Contracts which is what my example is doing. To describe ...
Joshua's user avatar
  • 101
11 votes
2 answers
250 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
  • 111
8 votes
1 answer
401 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
3 answers
232 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
7 votes
1 answer
141 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
2 answers
425 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
  • 1,009
7 votes
1 answer
145 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
2 answers
233 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
5 votes
2 answers
154 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
109 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
  • 682
5 votes
1 answer
217 views

How to interact between a smart contract written in Solidity from a smart contract written in ink!?

In the repository of the cargo-contract CLI tool, which currently "helps you develop smart contracts in Parity's ink!, which is a Rust eDSL allowing you to write smart contracts for blockchains ...
Luke Schoen's user avatar
  • 2,346
5 votes
1 answer
134 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
4 votes
5 answers
317 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
1 answer
89 views

Why are all the ink! Playground links broken in the official Substrate docs at substrate.dev?

If I go to https://substrate.io/developers/smart-contracts/ and click on any of the 6x hyperlinks called Open ink! Playground it takes me to https://ink-playground.substrate.io/ and returns 404 page ...
Luke Schoen's user avatar
  • 2,346
4 votes
1 answer
142 views

Rust ink. Division wont return a number with float point

I'm trying to calculate a value of token by using division operator, it will return a number higher then 1, but never returns here is the code of the price calculation: #[ink(message)] ...
yonatan hornstein's user avatar
4 votes
2 answers
468 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
  • 484
3 votes
2 answers
137 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(...
Alex Bean's user avatar
  • 5,757
3 votes
1 answer
111 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: ...
Rodrigo Paredes's user avatar
3 votes
1 answer
101 views

How to filter the subscribed contracts events with their topics?

I need to subscribe to my smart-contract events (#[ink(event)]). So I state_subscribeStorage to "System.Events" storage key. But then I get all system events of all smart contracts in my ...
Denis Glotov's user avatar
3 votes
3 answers
354 views

cargo contract throws error about supplied arguments in ` #[ink(constructor)]` for version 3.0.1

In my smart contract, all the ink dependencies are set to =3.0.1 because of this issue: Cargo contract 3.0.1 When I tried to execute the cargo contract build or even cargo +nightly contract build to ...
Jitterbug's user avatar
  • 219
3 votes
1 answer
239 views

How can I determine the native Balance of an Account/Address in Ink!

One can know the contract's native balance by using ink_env::balance() But, How can one know the native balance of a particular address/account in ink? For example, knowing the native balance of Alice,...
dharjeezy's user avatar
  • 419
3 votes
1 answer
169 views

Contract call returns error "Found input with 28 bits, expected 8". Polkadot.js and ink contracts

As the title suggest, I'm trying to call PSP22 token contract and read balanceOf() function, but I get error that I'm passing a too big of a input (27 instead of 8) When I initializing the token it ...
yonatan hornstein's user avatar
2 votes
1 answer
83 views

Cross-contract instantiation failed with TransferFailed

I am getting an error attempting to deploy my delegator smart contract. Not sure how to debug this issue. I use the deploy.sh to upload all smart contract code hashes and pass it afterwards to the ...
Snowmead's user avatar
  • 625
2 votes
3 answers
273 views

Ink! smart contract struct field issues

I am a Rust and Ink! novice so please bear with me but, I have a struct that looks like the following: #[ink(storage)] pub struct Contract { test: sp_arithmetic::FixedU128, } Unfortunately, I ...
eleidon's user avatar
  • 53
2 votes
1 answer
66 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 ...
forgetso's user avatar
  • 1,514
2 votes
1 answer
93 views

How do set the appropriate refTime and proofSize when create asMulti?

We had a big problem after upgrading weight -> weight v2. I understood that weight v2 uses refTime and proofSize. However, I wonder if there is a way to properly look up these two values. We are ...
hs1228's user avatar
  • 45
2 votes
1 answer
400 views

How to implement cross contract calls correctly?

I've been trying for a few days now to implement cross contract calls but somehow I can't seem to make it right. So here is my code and I hope one of you can point out my mistake to me. I want to call ...
rajohs's user avatar
  • 491
1 vote
1 answer
78 views

Cross-Contract Calls and Events don't work (ink 4.2.1)

I have replicate this error using the MultiContractCaller from the ink-examples In the multi_contract_caller we have a FakeEvent. #[ink(event)] pub struct FakeEvent { account_id: AccountId, } ...
Evil Kyle's user avatar
  • 149
1 vote
1 answer
106 views

Getting "Contract Reverted!" error with "TooManyTopics" dispatch error when calling mint function in OpenBrush PSP37 smart contract

I'm working on adding events to an OpenBrush PSP37 smart contract and deploying it using Substrate Contract UI. However, when I try to call the mint function, I encounter the following error: Contract ...
the dev's user avatar
  • 477
1 vote
0 answers
26 views

Why can't I still directly call method in sub-contract of basic-contract-caller example after removing method that allows calling from main contract?

In this commit of this Pull Request I'm using a modified version of this ink! basic-contract-caller example where there is a BasicContractCaller main contract and a OtherContract sub-contract. To run ...
Luke Schoen's user avatar
  • 2,346
1 vote
1 answer
82 views

Is it possible to override ink_env::test default block time?

Currently, in the ink test environment (ink_env::test), the default block time is 6 (see https://github.com/paritytech/ink/blame/50b32f4e49d4072f3d28009eb517475b68bec56b/crates/engine/src/ext.rs#L147) ...
Cromm's user avatar
  • 321
1 vote
1 answer
130 views

Unable to decode contract event: Unable to find event [closed]

Ive got this error on my console although transaction was succeeded. what causes this error..?
Steve's user avatar
  • 83