Questions tagged [rust]
Questions about the Rust programming language, the primary language used in the Substrate ecosystem.
264
questions
1
vote
1
answer
112
views
How do I work with SS58 encoded addresses?
I want to reason about SS58 addresses in any context with access to std, using Rust. What tools and techniques are needed to access the underlying keys?
[Related What is the SS58 Format?]
0
votes
0
answers
21
views
Type explanation [duplicate]
Can someone explain this type for me?)
type BalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
0
votes
2
answers
103
views
Duplicate lang item in crate `sp_io` when adding pallet_node_authorization (or any other pallet) impl section to the lib.rs
Adding the below section to the rs.lib file
impl pallet_node_authorization::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type MaxWellKnownNodes = MaxWellKnownNodes;
type ...
3
votes
1
answer
96
views
Error defining BoundedVec as a Pallet Storage the trait `Decode` is not implemented for `sp_runtime::BoundedVec
I have a StorageValue defined as follows
#[pallet::storage]
#[pallet::getter(fn reg_students)]
pub type RegStudents<T: Config> =
StorageValue<_, BoundedVec<StudentId, T:...
1
vote
1
answer
60
views
How can i resolve this weird error with StorageMap implementation?
I am trying to upgrade pallet-did to substrate v4 but i have an issue am facing with the StorageMap implementation. Below is the code for the storage map functions i am trying to implement:
#[pallet::...
0
votes
1
answer
38
views
State/storage does not get mutated [duplicate]
I have the following case:
let contract = Invoice {
origin: from.clone(),
to: to.clone(),
amount,
status: false,
id: 17,
msg: msg.clone(),
};
let mut invoice_vec: Vec<Invoice<T::...
7
votes
1
answer
227
views
usage parity-db instead of rocksdb
in the substrate-node-template case , I don't want to compile rocks-db at all. how it would be possible compile parity-db instead of rocks-db?
1
vote
0
answers
19
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<...
2
votes
1
answer
74
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 ...
3
votes
1
answer
272
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?
cargo build -v --release
...
1
vote
1
answer
101
views
How to mutate the value in storage?
let contract = Invoice {
origin: from.clone(),
to: to.clone(),
amount,
status: false,
id: 0,
msg: msg....
1
vote
3
answers
235
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 ...
4
votes
1
answer
182
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 ...
0
votes
2
answers
2k
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/...
2
votes
1
answer
40
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
56
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 --...
1
vote
2
answers
608
views
what does this line means #![cfg_attr(not(feature = "std"), no_std)]?
#![cfg_attr(not(feature = "std"), no_std)]
1
vote
1
answer
40
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 ...
0
votes
1
answer
190
views
Build error on substrate-node-template
I'm met with an error when running this command cargo build --release on substrate-note-template.
I haven't really done anything other than git clone to my directory and executed the cargo build ...
1
vote
1
answer
52
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 ...
2
votes
1
answer
43
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
73
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
80
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.
0
votes
1
answer
27
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&...
0
votes
2
answers
211
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
45
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, ...
0
votes
1
answer
51
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>
...
1
vote
1
answer
44
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 ...
1
vote
1
answer
748
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
0
votes
1
answer
114
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 ...
3
votes
1
answer
104
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 ...
0
votes
2
answers
98
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
80
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
52
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
116
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!
-2
votes
2
answers
131
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/...
1
vote
1
answer
270
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)
0
votes
1
answer
46
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 ...
2
votes
2
answers
605
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
62
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
87
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":"...
1
vote
1
answer
203
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!
0
votes
1
answer
132
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?
1
vote
0
answers
51
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() ...
2
votes
1
answer
76
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 ...
0
votes
1
answer
60
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"...
0
votes
1
answer
16
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 ...
0
votes
1
answer
45
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!
0
votes
1
answer
96
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 ...
0
votes
2
answers
92
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 ...