Questions tagged [ink]

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

Filter by
Sorted by
Tagged with
14 votes
3 answers
264 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 ...
  • 12.3k
12 votes
2 answers
155 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/...
9 votes
2 answers
177 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 ...
  • 91
9 votes
3 answers
172 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, ...
7 votes
3 answers
114 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 how to use it but not why it's needed. It seems more complicated to initialize and work with than the maps ...
6 votes
1 answer
72 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 ...
  • 169
6 votes
1 answer
97 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! ...
  • 393
5 votes
4 answers
244 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`). ...
5 votes
1 answer
104 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 ...
  • 393
5 votes
2 answers
119 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 ...
5 votes
1 answer
84 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 ...
  • 53
5 votes
1 answer
55 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
2 answers
82 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 ...
4 votes
3 answers
219 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
89 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
5 answers
221 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
2 answers
136 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?
4 votes
1 answer
134 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 ...
  • 105
4 votes
1 answer
69 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....
4 votes
1 answer
75 views

How to transfer funds via Currency(Balance Pallet) in ink! smart contract?

In ink! smart contract, we usually use AccountID and save the balances in array using mapping or HashMap. This is the traditional way of ERC20 smart contract. I am now developing on my local chain, ...
4 votes
1 answer
78 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)] ...
4 votes
1 answer
53 views

Using optional types in Ink! smart contracts and how to resolve in tests

Overview We are trying to test Ink! functions that leverage optional function arguments. Yet, it seems that the typescript tests don't play nicely with optional types. The encoding system is not ...
4 votes
1 answer
41 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 ...
  • 43
4 votes
1 answer
120 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 ...
4 votes
1 answer
72 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?
4 votes
1 answer
77 views

How to inform polkadot.js wallet to approve erc20-type token transfer? [closed]

I am developing smart contract that can stake erc20-type token, and testing it on shibuya testnet. But i have some problems. My staking contract have to request erc20-type token contract to approve ...
4 votes
1 answer
55 views

Rust Ink - Execution finished with debug buffer: panicked at 'called `Result::unwrap()` on an `Err` value: CalleeTrapped'

I'm trying to make cross contracts calls on already deployed contract, I'm running the local subtrate node in debug mode, and I'm getting the following message when trying to preform cross contracts. ...
4 votes
1 answer
126 views

How to make a stable coin on substrate?

I want to make a stable coin on substrate based chain, what I want to know is that can I do it with the assets pallet, as I can't find any function that peg it with any other collateral, if it is ...
4 votes
1 answer
61 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.
3 votes
3 answers
179 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 ...
3 votes
1 answer
59 views

How to enable chain extensions?

I have a chain extension implemented on substrate-contracts-node and in my ink! smart contract according to this tutorial. When I try to instantiate my contract on a local contracts-ui I get the ...
  • 4,412
3 votes
1 answer
38 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 ...
3 votes
1 answer
41 views

canvas-ui error on flipper.contract upload during substrate ink-workshop

When uploading the wasm binary, as a compiled smart contract on the 'ink-workshop' - the canvas-ui that I am running just errors. Canvas-ui error: Uncaught error. Something went wrong with the query ...
  • 55
3 votes
1 answer
47 views

polkadot canvas testnet contract deploy error "contracts.contractTrapped"

I'm trying to deploy basic erc20 example contract on rococo canvas but "contracts.ContractTrapped" error popped on deployment? most probably its a problem in INK release version I'm using ...
  • 131
3 votes
1 answer
84 views

Emiting events does not work with cross contract calling

When using cross contract calling on another contract which also emits events the events of the original contract do not work anymore. I get the following error. error[E0283]: type annotations needed ...
  • 182
3 votes
1 answer
100 views

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

as the title suggest, Im trying to call PSP22 token contract and read balanceOf() function, but i get error that im passing a too big of a input (27 instead of 8) Im trying to invoke balanceOf() PSP22 ...
3 votes
1 answer
41 views

Build Issues when implementing PSP22 token standard for ink! contract

I am trying to implement the PSP22 token standard but getting errors when building my contract. The errors are: #[brush::contract] | ^^^^^^^^^^^^^^^^^^ use of undeclared crate or module ...
  • 157
3 votes
1 answer
73 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?
  • 195
3 votes
1 answer
56 views

How to return error from chain extension?

I saw how to handle error from chain extension on smart contract side https://paritytech.github.io/ink-docs/macros-attributes/chain-extension#error-code But I can't find example and can't understand ...
  • 41
3 votes
1 answer
77 views

How to access environmental information about a contract from within a chain extension?

When we have an Ink! smart contract code calling a chain extension, how do we receive this information from within the chain extension: The calling smart contract address/ID The original caller of ...
  • 165
3 votes
2 answers
63 views

How to take file inputs from user on ink?

I want to take a csv input from the caller so that the csv contents can be loaded to the contract storage as a Vector. Crates like csv seem to do just that in standard Rust, e.g. using std::io or std::...
3 votes
1 answer
102 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 ...
  • 157
3 votes
1 answer
72 views

Custom Data Struct in Ink!

I have some questions that about custom data structure in ink!. https://paritytech.github.io/ink-docs/faq#what-are-the-scaleencode-and-scaledecode-traits. I already implemented some features with ...
2 votes
2 answers
82 views

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

I'm trying to do the signature verification in an ink! contract. I'm using ink_env::ecdsa_recover for this purpose. It is returning Compressed Public Key of type [u8; 33]. I have the AccountId of the ...
  • 393
2 votes
1 answer
65 views

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

I defined the ink! method and struct like this: #[derive(SpreadAllocate, PackedLayout, SpreadLayout, Clone, Decode, Encode)] #[cfg_attr(feature = "std", derive(Debug, scale_info::TypeInfo, ...
2 votes
2 answers
113 views

Panic in Ink! Smart Contracts

I want to find out how exactly "revert" works in ink! smart contracts: What happen if we panic!() in ink! contracts? IIRC we shouldn't use panic!() in runtime. Is there any difference ...
2 votes
2 answers
29 views

Get instantiated contract address from deployer contract

In the example the returned type is a reference to a contract which implements the FromAccountId trait. I would like to just have the contract address (AccountId) stored so that the frontend can ...
2 votes
2 answers
154 views

Can you query the state of a contract at a given block number?

I was wondering if its possible to query the state of a contract at an old block?
  • 53
2 votes
2 answers
57 views

How to receive multiple parameters of different types in chain extension

As ink chain-extension example https://github.com/paritytech/ink/blob/master/examples/rand-extension/runtime/chain-extension-example.rs#L32 . It show how to receive one param. But if I want receive ...
2 votes
1 answer
84 views

Ink! smart contracts and extrinsics [closed]

We have not had the chance to study ink! sc yet. A basic question I have is the following. In terms of an EVM deployed sc we rely on the parachain offering primitives in the form of precompiled and ...
  • 133