Skip to main content

Questions tagged [rust]

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

Filter by
Sorted by
Tagged with
14 votes
2 answers
2k views

Why do we need #![cfg_attr(not(feature = "std"), no_std)]

This attribute is applied to the item it is defined in and conditionally applies the no_std attribute if we are not using the "std" feature. Why do we need this and in which cases would the ...
infinitesimallySmart's user avatar
11 votes
3 answers
659 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
435 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
6 answers
424 views

How to call extrinsic functions externally from rust?

I need to call extrinsic functions, for example utility -> batch(calls) or utility -> batchAll(calls). Which library do I need to use for this? I can't find those examples in the web.
rdovgan's user avatar
  • 101
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
9 votes
2 answers
314 views

Trait bounds not satisfied for `Balance` type

I was following this guide Configuring Genesis for Balances. In my parachain, I replaced T::Balance with BalanceOf<T> type BalanceOf<T> = <<T as Config>::Currency as ...
Russo's user avatar
  • 1,193
9 votes
3 answers
204 views

Error adding Custom RPCs for pallet

I've been trying to add some rpc calls available for my node, but an error related to the 'getrandom' module appears (even tho I'm not even using it). I have a very simple pallet that creates and ...
andresvsm's user avatar
  • 1,114
8 votes
1 answer
150 views

How to setup and RPC call that accepts a u128 input?

I cannot seem to setup a RPC call that accepts a u128 param. I can input the following let u128Input = new BN("10") let output = await api.rpc.template.testRpc(u128Input); but get an error ...
drbh's user avatar
  • 83
7 votes
2 answers
173 views

What is Gossamer and how does it compare to Substrate?

Gossamer is a Go-lang implementation of the Polkadot host. What does this mean, and how does this compare to Substrate? Could Gossamer be the Go-variant of Substrate for developers exploring ...
q9f's user avatar
  • 307
7 votes
1 answer
213 views

How do I verify a signature signed using Polkadot.js app with rust code

I am trying to write a discord bot using rust/serenity to verify signature signed using polkadot.js app. I use schnorrkel crate, wrap the message in <Bytes>...</Bytes> and use the verify ...
Ankan's user avatar
  • 335
7 votes
1 answer
157 views

How to perform arithmetic operation on Option<BalanceOf<T>>?

Hello all developers and community members, I am very new to Substrate and Rust. I am creating a pallet for NFT marketplace. for storing out the NFT details I've created a struct as mentioned below. ...
Kapil Yadav's user avatar
7 votes
1 answer
113 views

How to programmatically get current unbonding information on the Polkadot relay chain?

Using either a Rust or JavaScript client library I would like to get the amount of DOT that is currently being unbonded on the relay chain. Some staking information is available in the Polkadot JS ...
Rtsne42's user avatar
  • 379
7 votes
1 answer
274 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?
kayvan jam's user avatar
7 votes
1 answer
173 views

Filter Events with subxt over multiple threads

I'm working on a project that uses Substrate in the backend. The System I am working on is written with Elixir and so I have a rustler NIF (Erlang/Elixir Native Function interface) for interacting ...
Tensor's user avatar
  • 73
6 votes
1 answer
312 views

With subxt how can I subscribe to watch extrinsics?

There's some great examples of how to use subxt to listen to all events. Polkadot-js events screen seem to show events grouped by the extrinsic that created them. Can I do the same in rust? (if not ...
Squirrel's user avatar
  • 3,849
6 votes
2 answers
739 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?
Sam Elamin's user avatar
  • 1,223
6 votes
1 answer
80 views

Is it possible to extend Prometheus metrics in Substrate?

Is it possible to register custom metrics to be exported via Prometheus? Specifically, we would like to write values specific to the runtime - e.g. TVL, average throughput, etc..
Gregory Hill's user avatar
5 votes
2 answers
108 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
440 views

Is possible to extract the runtime version from WASM file?

Is possible to extract the runtime version from the WASM file? Sometimes, I want to verify the WASM file's content locally.
AurevoirXavier's user avatar
  • 10.5k
5 votes
1 answer
248 views

How to set base_fee and len_fee to zero?

I was trying to modify the transaction fee and for that I only want the congestion of the network. In FeeDetails, that is present in the transaction-payment pallet, we have three fields, i.e., ...
Shubham Gupta's user avatar
5 votes
1 answer
73 views

How to I submit UTF-8 text to an extrinsic?

I'm making a pallet that takes a string as the input. I tested it and it works well with English words, but when I try Vietnamese, the input box turned red and I couldn't submit the extrinsic. How can ...
Minh Mốc's user avatar
  • 1,009
5 votes
1 answer
764 views

Cannot infer type for type parameter 'T'

I have a function using the following 2 types: pub type BalanceOf<T> = <<T as pallet::Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance; pub ...
Kazunobu Ndong's user avatar
5 votes
2 answers
153 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
3 answers
288 views

Missing trait problem

Hello the following code snippet is giving me headaches: mod items; pub use super::*; pub use crate::roles::items::*; pub type BalanceOf<T> = <<T as pallet::Config>::Currency as ...
Kazunobu Ndong's user avatar
5 votes
2 answers
196 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
146 views

How to create an iterator for a child storage trie?

I have a Storage Map which I am using to to store structs and a Storage Value to use for indexing this: #[pallet::storage] #[pallet::getter(fn consequences)] /// Storage map holding basic Consequence ...
jpataylor's user avatar
  • 321
5 votes
2 answers
166 views

Logging best practice for pallet extrinsics

What is the best practice for logging in pallets? Is there any overhead leaving them in at a debug/trace level? Or should we never use them outside of development? e.g. log::debug!("")
Robert La Ferla's user avatar
5 votes
1 answer
312 views

Build a docker file/image for my new pallet

I am using substrate-node-template and recently I added a new pallet. Now I need to build a docker file because I would like to send it for testing. Any information? Thank you.
P.E's user avatar
  • 181
4 votes
2 answers
206 views

std in conditional compilation [closed]

#![cfg_attr(not(feature = "std"), no_std)] Does the "std" above reflect the rust standard library or the std feature defined in the cargo.toml for a given crate? Also, for many of ...
infinitesimallySmart's user avatar
4 votes
1 answer
371 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
1 answer
141 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
3 answers
95 views

Build the Substrate Kitties Chain Tutorial Cargo Error

I was following the tutorial: https://docs.substrate.io/tutorials/v3/kitties/pt1/ and as said in the tutorial I installed kickstart using: cargo install kickstart And after that cloned a copy of the ...
Ajit's user avatar
  • 827
4 votes
1 answer
81 views

usage of `#[pallet::constant]` vs `const associated item`

I can have config of my pallet in two different ways: trait Config: frame_system::Config { // *--snip #[pallet::constant] SomeConstant: Get<u32>, const ANOTHER_CONSTANT: u32, } ...
Dev-il's user avatar
  • 69
4 votes
2 answers
1k views

error[E0512]: cannot transmute between types of different sizes, or dependently-sized types

I am using the latest substrate-node-template few weeks back it was building fine. But the same project isn't building now, I did not do any changes. Error is occurring in runtime interface. I am ...
Vjendra Gaorh's user avatar
4 votes
1 answer
249 views

How can I decode an extrinsic or event dynamically in rust?

How can I decode an extrinsic or event dynamically in rust? (I want to be able to decode across all parachains) A lot of the heavy lifting seems to be frame-metadata and scale-info. There's a desub ...
Squirrel's user avatar
  • 3,849
4 votes
1 answer
142 views

How do `subxt` and `substrate-api-client` libraries differ?

I understand that there are two main Rust client libraries for Substrate: subxt substrate-api-client I've checked out the examples for both libraries and it seems to me that they are mostly the same....
Rtsne42's user avatar
  • 379
4 votes
1 answer
96 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. ...
yonatan hornstein's user avatar
4 votes
1 answer
274 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 ...
Alex Bean's user avatar
  • 5,722
4 votes
1 answer
232 views

T::Balance ... associated type `Balance` not found for `T`

I was following this guide: Configuring Genesis for Balances https://docs.substrate.io/how-to-guides/v3/basics/genesis/ but got this error: associated type Balance not found for T, associated type ...
Russo's user avatar
  • 1,193
4 votes
2 answers
143 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
  • 121
4 votes
1 answer
62 views

Pallet generate store is deprecated how to avoid this warning and compile the code?

I am getting error in #[pallet::generate_store(pub(super) trait Store)] which is showing deprecated warning due to which I could not compile my custom pallet is there any solution
Parth Kohli's user avatar
4 votes
1 answer
154 views

Is there any way to access the accountid inside the offchain worker?

I am coding a pallet in which I need to know who I am inside a offchain worker to check if I should send a transaction or not. Right now I have access to the account in the send_signed_transaction ...
Gabriel Martinez's user avatar
4 votes
2 answers
58 views

WebAssembly runtime file into ValidationCode

I have a CLI tool that gets a WebAssembly runtime file: let validation_code_content = fs::read_to_string(path_validation_code) .expect("Should have been able to read the validation code ...
Alex Bean's user avatar
  • 5,722
4 votes
1 answer
24 views

error[E0282]: type annotations needed --> /libp2p-noise-0.32.0/src/protocol/x25519.rs:221:45

While running this project https://github.com/jimmychu0807/substrate-offchain-worker-demo I'm geting this error: error[E0282]: type annotations needed --> /libp2p-noise-0.32.0/src/protocol/x25519....
S Miss's user avatar
  • 41
4 votes
0 answers
186 views

How to solve this Failed to compact generated WASM binary.: Error(UnknownOpcode(192)) [duplicate]

For one assignment I have run the command cargo build --release so that I can build the pallet. After that I was getting the error After that according to this- Error Building Substrate contract Node(...
Nakul Agrawal's user avatar
4 votes
1 answer
111 views

How to parse an ss58 address in no_std rust

In another question How do I work with SS58 encoded addresses? the same question was addressed, this is however about how to do it without the std lib. How to convert an ss58 stored in a String to an ...
Simson's user avatar
  • 1,201
3 votes
1 answer
2k views

How to output debug log in `build.rs`? [closed]

I want to output some debug info in the wasm_builder, What is the right way to do this? We cannot use normally runtime log::debug!(...) approach here, as the build.rs is compiled with the node build ...
boundless-forest's user avatar
3 votes
2 answers
62 views

How can I have some of the functions in separate file?

I want to keep some helper functions in a separate file. How can I do that? impl<T: Config> Pallet<T> { fn get_citizen_accountid(citizenid: u128) -> fn get_citizen_id(...
Amiya Behera's user avatar
3 votes
1 answer
67 views

Why using value and value reference as parameter in functions of StorageValue and StorageMap are both OK?

In my coding, I find that I can use a value or a value's reference as parameter in function StorageValue::put(). The same case is in function StorageMap::insert(). In my view, I can not input a value ...
kugool's user avatar
  • 171
3 votes
1 answer
399 views

What is the difference between dependencies and dev-dependencies in Cargo.toml

My question is What is the difference between dependencies and dev-dependencies in Cargo.toml. And for developing pallet, now I have to declare crate in dependencies
Rong Nguyen's user avatar

1
2 3 4 5 6