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
11 votes
3 answers
668 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
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
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
4 votes
1 answer
282 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,757
4 votes
1 answer
376 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
1 vote
1 answer
510 views

Substrate Rust generate key pair using sp_core::crypto::Pair

I'm pretty new with Substrate and Rust, but I was trying to generate a key pair using the from_string function of sp_core::crypto::Pair . I haven't had any luck and kept getting either ...
som3_l0cust's user avatar
10 votes
3 answers
444 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
9 votes
2 answers
317 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,207
8 votes
1 answer
154 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
6 votes
1 answer
318 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,899
5 votes
1 answer
252 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
4 votes
1 answer
142 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
1 answer
118 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,275
4 votes
2 answers
212 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
3 votes
1 answer
109 views

Division operation in `u128` results false value

In my node, Balance type is u128. I have following variable let per_block = 100_000_000_000_000_000_u128; let total = 50_000_000_000_000_000_000_000_u128; let ratio = per_block.checked_div(total); ...
Sudip Ghimire's user avatar
3 votes
1 answer
173 views

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

As the title suggest, I'm trying to call PSP22 token contract and read balanceOf() function, but I get error that I'm passing a too big of a input (27 instead of 8) When I initializing the token it ...
yonatan hornstein's user avatar
2 votes
1 answer
272 views

How to decode events help on substrate using polkadot.js?

I have a base smart contract in rust with package manager cargo. In that smart contract I have some events which I'm emitting while function calling. For listing that events I have a service in java ...
Puneet Jindal's user avatar
2 votes
1 answer
773 views

How to convert Vec<u8> to u32 in Substrate runtime?

AFAIK, we can't use std in Substrate WASM runtime, what is the most effective way to convert a string to a number in runtime. For example: string "48" in Vec to 48 in u32.
lucycollins's user avatar
2 votes
1 answer
109 views

MultiAddress to Address String

I'm trying to retrieve the author's address as a string, and I've successfully obtained the MultiAddress using the following code: let validator_address = if let Some(author_multi_address) = ...
Yeou's user avatar
  • 229
2 votes
2 answers
147 views

error: duplicate lang item in crate `std` (which `arrayvec` depends on): `panic_impl`

I am use the latest rust toolchain, compiler the pallet-ibc at the branch feature/dv-ics20 : https://github.com/octopus-network/substrate-ibc, this give the blow error. suyinrong@suyinrongdeMacBook-...
D.Davirain's user avatar
2 votes
1 answer
151 views

How to upgrade Frontier to use a specific Substrate version

The Substrate team(https://github.com/paritytech/substrate/) produces releases like polkadot-v0.9.25 every a few weeks, and my team needs to upgrade our parachain to follow those Substrate versions. ...
Russo's user avatar
  • 1,207
1 vote
3 answers
561 views

How can manually generate same address from mnemonic as subkey without it?

Can someone tell me how can I generate a secret/privateKey/miniSecretKey, publicKey without subkey the tool from a mnemonic? I am working on a c# implementation of the wallet generation and I'd ...
atesz's user avatar
  • 21
1 vote
1 answer
84 views

Calculate Session/Epoch time remaining

I've seen some websites display the estimated time remaining for the current session/epoch. Is there a Rust call for this? Is there a sample of that code?
CrackerJack9's user avatar
1 vote
3 answers
350 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 ...
P.E's user avatar
  • 181
1 vote
2 answers
3k 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/...
P.E's user avatar
  • 181
1 vote
1 answer
367 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)
P.E's user avatar
  • 181
1 vote
1 answer
145 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?]
Nuke's user avatar
  • 1,852
0 votes
3 answers
337 views

Mac m1 substrate node template can't be build

I get this issue when I try to build the substrate-node-template error: failed to run custom build command for `prost-build v0.10.4` Caused by: process didn't exit successfully: `/Users/elioprifti/...
P.E's user avatar
  • 181
0 votes
2 answers
93 views

Smoldot Documentation

How to run smoldot repository code and connect with our substrate based chain or substrate node ? On official documentation of smoldot on github is not in detail .Please answer here complete way to ...
user avatar
0 votes
1 answer
50 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 ...
raf's user avatar
  • 1
0 votes
1 answer
47 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")] ...
Shubham Gupta's user avatar
0 votes
1 answer
104 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 ...
Steve's user avatar
  • 83