Questions tagged [rust]

Questions about the Rust programming language, the primary language used in the Substrate ecosystem.

Filter by
Sorted by
Tagged with
1 vote
0 answers
4 views

BoundedBTreeMap error with Debug trait

Consider the following snippet #[weight = 100_000_000] //TODO: update weights pub fn test( _origin, _outputs: frame_support::BoundedBTreeSet<JoyBalanceOf<...
  • 59
0 votes
0 answers
22 views

What is the smartest way to make multiple dynamic storage queries using subxt?

Is it possible to make batched storage calls to the runtime using subxt or is it only possible to make repeated individual calls against the state? Say there are 3 storage variables I would like to ...
0 votes
0 answers
36 views

build failed with substrate chain on rocksdb in linux

I followed this tutorial https://docs.substrate.io/tutorials/get-started/build-local-blockchain/. I got the below error when run cargo build --release. How can I fix it? error occurred: Command "...
1 vote
1 answer
20 views

How to mutate the value in storage?

let contract = Invoice { origin: from.clone(), to: to.clone(), amount, status: false, id: 0, msg: msg....
  • 81
0 votes
0 answers
33 views

How to use event to show my Vec items? [closed]

I do have a Vec and I would like to show all the items in event. If I try to loop the Vec and emit an event for every item it will show only the last value of Vec. How can I emit the whole Vec? An ...
  • 81
0 votes
1 answer
21 views

How to store a list of items in Substrate? [closed]

The question is very clear. Do you recommend using Vec?
  • 81
0 votes
2 answers
30 views

How to store a string in substrate storage?

I would like to store a string/message in substrate storage because I am writing a pallet, later on, I would like to use the Polkadot.js portal to write the message on the front-end and store it, and ...
  • 81
2 votes
1 answer
34 views

Balance division in Substrate runtime

I am a bit confused with how to do operations with the Balances in the Substrate runtime. More concrete the division. The example I want to implement is similar to the Lottery pallet but with shared ...
  • 1,039
0 votes
1 answer
104 views

error: linking with `cc` failed: exit status: 1 (Mac m1)

Not able to build a project because of this issue: error: linking with `cc` failed: exit status: 1 | = note: "cc" "-arch" "arm64" "/var/folders/5w/...
  • 81
1 vote
1 answer
17 views

How to provide argument to storage call in subxt?

In polkadotjs I have following code: const opts = [{"UniqueIdenfier1":[0,"challengeprofile"]}] let data = api.query.templateModule.periodName( ...opts, ...
0 votes
2 answers
32 views

Failed to build substrate-node-template using Macbook pro M1 pro

Im unable to build substrate-node-template using my Macbook pro M1 Pro laptop. I updated cmake and followed the official guide: https://docs.substrate.io/quick-start/ I also tried with the flag --...
2 votes
2 answers
32 views

what does this line means #![cfg_attr(not(feature = "std"), no_std)]?

#![cfg_attr(not(feature = "std"), no_std)]
1 vote
1 answer
20 views

Error when Adding weight related configurations

I'm in the process of configuring weights for a pallet pub struct GymWeight<T>(PhantomData<T>); impl<T: frame_system::Config> WeightInfo for GymWeight<T> { fn ...
  • 131
0 votes
1 answer
29 views

Build error on substrate-note-template

I met with error when running this command cargo build --release on substrate-note-template. I haven really do anything other than git clone to my directory and run the cargo build mentioned above. ...
1 vote
1 answer
47 views

Does it make sense to store it in blockchain? [closed]

I was looking for an idea to build on Substrate and I found out this product built on Ethereum: https://create.request.network/ In a few words is an invoice system that creates/pays invoices between ...
  • 81
0 votes
1 answer
14 views

Signed bytes from Schnorrkel library throws Bad Signature error

Hey i have some call data which is similar to this. I am signing it using schnorrkel libaray function function. as secret.sign_simple(&[], msg) where secret is a Keypair and msg is in bytes. Then ...
0 votes
1 answer
34 views

Polkadot/Substrate estimate tx fee from Rust

In the polkadot js/ts library there is a method to estimate tx fee: const info = await api.tx.balances .transfer(recipient, 123) .paymentInfo(sender); We want to do the same (estimate tx fee) ...
1 vote
1 answer
31 views

Event encoding in substrate pallet

Can two pallets have exactly same event name and event parameters. If yes then is there a way to distinguish the event came from which pallet in golang.
  • 21
0 votes
1 answer
15 views

How to avoid the wildcard Import?

I want to remove this wildcard import, but don't know how to do. I am working on the "pallet/xxx/src/lib.rs", while this file is very similar to the one from "substrate-node-template&...
  • 37
0 votes
2 answers
31 views

Create a signed transaction using a signature and unsigned_transaction

I have two functions. The first function: Generates payload of unsigned_transaction: The second function: Needs to generate a signed transaction, using unsigned_transaction and signature. Process: ...
0 votes
0 answers
35 views

Error building the parachain template - 2 [duplicate]

I was compiling the runtime by cloning this source, https://github.com/szout/substrate-parachain-template, but at the moment I met this issue. I tried to solve this issue by referencing these QAs, ...
  • 37
0 votes
1 answer
23 views

How to use Mapping with Sha2x256 in ink smart contracts

I want to try and use Mapping with Sha2x256 or any other value that is large enough so that each of these will be unique. I want mapping to be like this: unique_ids: Mapping <Sha2x256 ,u128> ...
  • 11
1 vote
1 answer
31 views

Split extrinsic execution across multiple blocks

Is it possible to split the execution of an extrinsic into several continuous blocks? Looking at this post, it is possible to create migrations, but I was wondering if the same can be applied to an ...
  • 957
1 vote
1 answer
124 views

How i implement Debug for trait object [closed]

I find out 1 piece of code in substrate pub struct IsValidator(Box<dyn Fn() -> bool + Send + Sync>); How can I implement Debug for IsValidator Struct
  • 354
0 votes
1 answer
41 views

Substrate AUTHORIZATION pallet runtime issue

I am having a versioning issue with the AUTHORIZATION pallet. I pushed all my changes in the authorization_issue branch: https://github.com/herou/ferrum-x-network-elio/tree/authorization_issue I am ...
  • 81
3 votes
1 answer
37 views

Code coverage setup in Substrate

At my current company we are using Substrate for our developments, we have an automated setup with test and whatnot. We are now evaulating our options regarding code coverage. We are thinking of a ...
  • 33
0 votes
2 answers
29 views

How to set timestamp in benchmarks?

Is it possible to use std for benchmarks? If not, how can I get timestamps in a benchmark? I tried using this but it didn't compile: #[cfg(feature = "runtime-benchmarks")] extern crate std;...
0 votes
1 answer
33 views

Decoding extrinsic hex into readable form in Rust

I am running the substrate-dev node. Made a transaction using Polkadot-explorer. After fetching the block using subxt I am getting extrinsic hex as: ...
0 votes
1 answer
33 views

iter storage in substrate

I Wanna to create a StoreBasket in Substrate . I Have Two Struct one for BusinessItem . #[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] #[scale_info(skip_type_params(T))] #[codec(...
0 votes
1 answer
71 views

How to Configure a testnet for my substrate chain?

I would like to set up a testnet for my substrate chain. I did not find much information around. Can you please help me with articles/tutorials? Thank you!
  • 81
-2 votes
2 answers
52 views

expected enum `Result<_, pallet::Error<T>>` [closed]

I write codes for add item in storage but when I run this command cargo build --release it show me this error : error[E0308]: `match` arms have incompatible types --> /home/kianoush/projects/...
0 votes
1 answer
52 views

How to connect substrate node to metamask?

My node is compatible with EVM and I would like to connect it to metamask? How can I do it? What should I put in RPC URL and chain id? (Where can I find my chain id)
  • 81
0 votes
0 answers
24 views

Delegator-based contract causes UI interface to crash

I have a funny problem, hopefully, someone can help. I have an environment similar to the delegator example contract: one delegator-like contract, one accumulator-like contract, and one adder-like ...
  • 1
1 vote
1 answer
207 views

Convert a H256 string to H256

I have a hash string "0xf8dd02cc2a3174933fac4e87d7f6360c3cc67167db105b28d0bc434a60674e49". How can i convert back to H256. I used function below but it return difference H256 ...
2 votes
1 answer
25 views

Deciphering a complex type declaration for AccountId

This code is from common/primitives/src/node.rs in Substrate. Can someone do a part by part break down of this type and explain the intent of each part and the overall intent? pub type AccountId = &...
0 votes
1 answer
50 views

RPC custom request/response

Currently using Postman I can make requests to my node and get a response. The code below is a request: { "jsonrpc":"2.0", "id":3, "method":"...
  • 81
1 vote
1 answer
29 views

What are the latest minimum specs for running a Substrate node?

I do have an old laptop and I would like to know the minimum specs for running a Substrate node. This node should be also a validator. Thank you!
  • 81
0 votes
1 answer
39 views

How to get data to off-chain worker from runtime?

Is any option to get data to off-chain workers from runtime? For example, I have used runtime to store something. How can I access this data from off-chain woker without using HTTP calls?
  • 81
0 votes
0 answers
36 views

Call a smart contract method from the offchain worker

As the title is descriptive I would like to call a method on a Sample contract deployed to runtime evm, from the off-chain worker. For example: Contract Sample { Public five=5; } Call Sample.five() ...
  • 81
2 votes
1 answer
26 views

storage double map key deletion

Consider a substrate double map pub Foo get(fn category_by_moderator): double_map hasher(blake2_128_concat) T::K1, hasher(blake2_128_concat) T::K2 => T::V; Suppose I want to delete all ...
  • 59
0 votes
1 answer
53 views

I got this error when I converted HashMap to Mapping

As you can see here, I have changed HashMap to Mapping. Then I got a lot of errors like this, does it mean that there is no entry in Mapping? version is bellow ink_storage = { version = "3.3"...
  • 51
0 votes
1 answer
15 views

Cannot reference a value that should have been mapped

Sorry for the rudimentary question, I'm new to Rust and ink! I get a lot of errors when I run cargo +nightly contract test. I have checked the official site for the usage of ink_storage::Mapping, but ...
  • 51
0 votes
1 answer
29 views

Best way to connect my substrate node with android app

I do have a native app written in Java/Kotlin and I would like to connect it with my substrate node. Which is the best way to do it? Any open-source library? Thank you!
  • 81
0 votes
1 answer
64 views

#[ink(constructor)] cause a error, What is wrong with it?

error: encountered unexpected ink! attribute --> lib.rs:80:15 | 80 | #[ink(constructor)] | ^^^^^^^^^^^ when I execute $cargo +nightly contract test , the above error ...
  • 51
0 votes
2 answers
39 views

No slash after the validator is offline

There is a condition in the substrate for the validators like if the validator misbehaves for example if the validator goes to offline than the stake of the validator will be slash, I setup a network ...
5 votes
2 answers
230 views

How do I move my USDC/USDT to statemine?

Hi I heard USDT and USDC is now on statemine. How do I get access to that? Assuming I have USDT on my ERC20 wallet, how do I get that to a substrate-based chain/parachain?
0 votes
1 answer
20 views

How can I access a value obtained at runtime in primitives npos elections?

I want to change the weight/score of targets on the basis of values got during runtime, in my research I found the score of a target is being calculated in primitives/npos-elections/phragmen.rs in fn ...
0 votes
0 answers
32 views

How to convert str type to AccountID type? [duplicate]

Personally, while writing the Treasury contract, it was necessary to change the string type to the account ID type. Even if I google how to do it, I can't find a proper solution, so I'm curious what ...
0 votes
1 answer
27 views

How to use code written in `std` in `no_std` during runtime?

I have a piece of code written in std, and it is bypassing/not-included in runtime as it should work but I want to use it in runtime environment, is there a way to use it. As the code written in std ...
0 votes
1 answer
34 views

Compiled code withe #[cfg(feature = "std")] and facing issues while setting up staging environment

I have compiled my code successfully and it is running fine in development mode, when I make the staging environment for the same with 3 nodes the code written inside #[cfg(feature = "std")] ...