Questions tagged [smart-contract]

Everything smart contract related, either WASM or EVM based.

Filter by
Sorted by
Tagged with
22 votes
3 answers
695 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
  • 15.8k
11 votes
2 answers
183 views

Wasm interpreter in pallet-contracts

I have a question about how pallet-contracts interprets a Wasm contract. Are the following assumptions correct? pallet-contracts interprets contracts through the simple wasmi interpreter gas metering ...
Torsten Stüber's user avatar
11 votes
2 answers
262 views

How to upgrade a smart contract logic?

I deployed a smart contract to a substrate chain. How can I upgrade the smart contract's logic to a newer version? Edit: I'm using ink! and deployed on Shibuya (Astar testnet)
Minh Mốc's user avatar
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, ...
edmassarani's user avatar
10 votes
3 answers
365 views

Why is it a bad idea to use String in an ink! smart contract?

I've heard that it is a bad idea to use Rust's String type in an ink! smart contract. Why is this so? And what is your recommendation to use instead for typical use cases of String ‒ so parsing input ...
user16756428's user avatar
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 ...
Dream's user avatar
  • 101
9 votes
1 answer
73 views

Incorrect display name for smart contracts numeric return types

When I deploy an ERC20 on Polkadot JS Apps, i can see that the return type of total_supply is u128, however according to the contract metadata it should display Balance. Noticed also for ERC1155 ...
Andreea Eftene's user avatar
9 votes
1 answer
117 views

Smart Contract blockspace allocation in Hybrid Chains

In Rob Habermeier's blogpost about Hybrid Chains, he mentions allocating contract execution to a limited fraction of the chain's blockspace. Is that some functionality that pallet-contracts provides? ...
Bernardo Rodrigues's user avatar
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`). ...
Kar Keung Christopher Fok's user avatar
8 votes
1 answer
92 views

Performance of same logic with a contract using pallet-contracts vs. a native pallet (excluding metering)

I'm wondering what is current state of the art of Substrate's pallet-contracts performance as compared to the same functional implementation as a pallet. I acknowledge that different logic can have ...
nazar-pc's user avatar
  • 539
8 votes
4 answers
143 views

Managing deployment of complex set of wasm contracts

We need to deploy a set of several smart contracts, x-compiled from Solidity to wasm, and maintain that deployment (deploy new contract instances and migrate to them once in a while). So what we ...
Andy Wermke's user avatar
8 votes
1 answer
294 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
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?
Minh Mốc's user avatar
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 ...
Maario's user avatar
  • 659
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 ...
Alejandro Martínez's user avatar
6 votes
2 answers
195 views

cross contract call failure when using different salt to instantiate contract

I tried deployed two ink-compatible solidity smart contract using solang as the compiler. When trying to play around cross contract calls, I've stumbled upon the below failure: Prerequisite: compile ...
extraymond's user avatar
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 ...
ExplodingJay's user avatar
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?
fbielejec's user avatar
  • 331
5 votes
2 answers
711 views

smart contract function call error

I am deploying flipper ink! smart contract to shibuya, but when I tried to read the value using get() I am getting this error: { Err: { Module: { index: 70 error: 0x02000000 } } } I also tried ...
jefry's user avatar
  • 53
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 ...
yonatan hornstein's user avatar
5 votes
1 answer
429 views

How can I call my contract methods inside a pallet?

Can someone tell me how can you execute a smart contract method inside your custom pallet? You can call your smart contract tx/query through the RPC API but how can you call it inside a custom pallet? ...
hgminerva's user avatar
  • 467
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::...
Pierina Ponce's user avatar
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?
Bernardo Rodrigues's user avatar
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-...
yonatan hornstein's user avatar
5 votes
1 answer
144 views

Why does the Astar XC20 wrapper example use the ERC20 wrapper functionality?

I am working on an XC20 implementation of an existing ERC20. I am basing the contract off of the Astar here. I noticed there is some code inherited from the ERC20 contract via the ERC20Wrapper ...
DanTheMan's user avatar
5 votes
1 answer
118 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 White's user avatar
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 ...
ebma's user avatar
  • 53
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 ...
goastler's user avatar
  • 549
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 ...
Denis Glotov's user avatar
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 ...
george huang's user avatar
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.
ExplodingJay's user avatar
5 votes
0 answers
74 views

I want to use Parity SCALE codec in Solidity? Is there any implementation of scale codec to decode bytes?

I want to decode bytes on the Solidity side that was decoded with scale codec. Is the any implementation of scale codec (decode) on the Solidity side?
rust.dev's user avatar
  • 509
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.
Mehdi Raash's user avatar
4 votes
2 answers
552 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
1 answer
127 views

What is "value" and "storageDepositLimit" in contract call?

After I called a contract, this is the extrinsic I found in the block: What do these fields mean: value, storageDepositLimit ?
Minh Mốc's user avatar
4 votes
1 answer
101 views

Encode strings to SCALE encoded smart contract calls

I'm looking for a way to encode smart contract calls in javascript code with polkadot-js, the same way I can do it from the web UI, but I cannot find a description of the available API in the ...
Simson's user avatar
  • 1,080
4 votes
1 answer
197 views

Caching of smart contract storage reads

Wanted to get some clarity on repeated reads. Assuming this is the contract storage, two values both under the default 0x00000000 key in the storage. #[ink(storage)] pub struct MyContract { pub ...
fbielejec's user avatar
  • 331
4 votes
1 answer
121 views

cargo-contract throws on a valid WS URl

Most recent version (v1.3.0) of cargo-contract does not parse a valid WS url: cargo +nightly contract upload --suri '//Alice' --url 'wss://ws-smartnet.test.azero.dev:443' ERROR: Rpc error: Networking ...
fbielejec's user avatar
  • 331
4 votes
1 answer
67 views

Is there a substrate node that contains pallet-contracts and uses instant seal consensus?

I've seen instant seal mentioned as a way to get transactions sealed by the substrate node upon receipt. I also know that moonbeam have this in their node. Is there a substrate node that includes ...
forgetso's user avatar
  • 1,462
4 votes
1 answer
122 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 ...
Angel Brett's user avatar
4 votes
1 answer
253 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
262 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
4 votes
1 answer
66 views

How to see the parameters that were passed into a contract call?

I want to know the contract address, contract caller, and what parameters were passed into the contract call but in the Polkadot.js UI, the presented fields don't seem to be helpful.
Minh Mốc's user avatar
4 votes
1 answer
82 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,292
4 votes
2 answers
87 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 ...
Woodfish's user avatar
  • 111
4 votes
1 answer
63 views

rococo-contracts-rpc.polkadot.io, upgrade their nodes to the latest avaliable version

Does anyone know when the rococo-contracts-rpc.polkadot.io is going to upgrade their nodes to the latest available version ? Error: Ink version:
Evil Kyle's user avatar
  • 149
4 votes
1 answer
49 views

How to compile to wasm and deploy a custom pallet instead of an ink! smart contract to the Contracts module/pallet?

I enjoy writing custom pallets so I would like to know if instead of writing an ink! smart contract and then compiling it to .wasm and deploying it to the Contracts module/pallet of a Substrate-based ...
Vinh Real's user avatar
4 votes
1 answer
34 views

How can i query pallet contract to give the Scale codec value of a Contract Root Storage Key

According to ink!: "Storage data is always encoded with the SCALE codec. The storage API operates by storing and loading entries into and from a single storage cells, where each storage cell is ...
dharjeezy's user avatar
  • 419
3 votes
2 answers
96 views

Is there any way to verify ink smart contract

I need to verify the ink smart contract code with deployed contract. Just like solidity verification. Anyone can give me a clue how to do so and any existing tool?
Brian Nguyen's user avatar
3 votes
2 answers
480 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 ...
Daniel Lam's user avatar

1
2 3 4 5 6