Skip to main content
11 votes
Accepted

What's the best way to compute square root in Substrate?

If you are just after the integer sqrt (which, depending on your use-case, may be enough), you could follow the approach that the democracy pallet does. In this case it uses integer_sqrt::...
Jaco's user avatar
  • 5,865
8 votes

What's the best way to compute square root in Substrate?

TLDR: sp-arithmetic for relatively simple use cases as highlighted in this answer, and substrate-fixed for more advance stuff. To perform non-deterministic arithmetic like division and square roots, ...
islami00's user avatar
  • 561
4 votes

How can I read JSON files in substrate

You definitely should not do this. You cannot use std inside the runtime. The Substrate runtime does not have access to the file system of the computer, so any kind of File::open stuff is definitely ...
Shawn Tabrizi's user avatar
  • 16.1k
3 votes
Accepted

Why is serde always std-gated in substrate?

First, we need to acknowledge the std feature flag in Substrate is very imperfect. It represents both a separation of std from no_std, but it also USUALLY implies wasm. It has been noted before that ...
Shawn Tabrizi's user avatar
  • 16.1k
3 votes
Accepted

Trying to implement Substrate client on IoT, any suggestions?

I think making subxt be no std compatible would seem to be the best way to go. https://github.com/paritytech/subxt/issues/208 No one has yet given it a crack with a PR, but all the on chain code is ...
Squirrel's user avatar
  • 3,849
3 votes
Accepted

How to execute an ELF binary after a successful transaction

There is no solution for this (yet). An API for executing binaries from the OCW could be introduced, but allowing a runtime to execute arbitrary binary code on essentially any node on the network is a ...
Gav's user avatar
  • 2,681
3 votes

How to execute an ELF binary after a successful transaction

OCW could theoretically help, but Substrate does not provide a way to launch a program in response to some event. However, OCW can send HTTP requests. When OCW discover the transaction of interest it ...
pepyakin's user avatar
  • 2,184
3 votes

How to enable `std` features in pallets?

standard library macros are (for some reason) out of scope. TL;DR: you cannont use std in runtime development As you see on the node template all runtime files must not use std because they target ...
Nuke's user avatar
  • 1,842
2 votes
Accepted

Pallet Fails to Build Because of `std` Macros

I fixed it. First let me explain how I got this error. I cloned Kulupu's difficulty pallet. And it required Kulupu's primitives as one of the dependencies. So I cloned them as well so the Cargo.toml ...
CREESTL's user avatar
  • 484
2 votes

Trying to implement Substrate client on IoT, any suggestions?

You can see a list of tools here: https://docs.substrate.io/v3/integration/client-libraries https://github.com/substrate-developer-hub/awesome-substrate#tools Note that some are actively maintained, ...
Bruno's user avatar
  • 8,315
2 votes
Accepted

error: `#[panic_handler]` function required, but not found

You are not using anything from sp_io in your lib.rs. The crate is therefore not linked in and you are missing the panic handler in your binary. Add this to lib.rs to pull it in: extern crate sp_io;
Alexander Theißen's user avatar
2 votes

Why not implement the sp_std::fmt::Debug for AccountId32 in non-std

This was done to reduce the size of the wasm runtime. However, it could probably be revisited on what are the gains of not having them in wasm.
bkchr's user avatar
  • 11.6k
2 votes

Use std only rust library to extend substrate runtime interface?

Yes you can use runtime-interface to create a host function that calls your rust library. However, you need to be aware that any call to the host is not for free and adds some overhead. You also need ...
bkchr's user avatar
  • 11.6k
1 vote
Accepted

Is there a way to use a crate that depends on the `std` in substrate OCW?

I'm not sure why it was designed this way, but I understand how it works. Perhaps they intended for the OCW to run anywhere since it's part of the WASM blob. Therefore, everything is compiled into ...
AurevoirXavier's user avatar
  • 10.7k
1 vote

Get results of some std operations in benchmarks

Ultimately, there's no "right" way to do it. Some script outside of the benchmark would have to be run to generate the values. Here's a FRAME example where primitive types such as keypairs ...
Justin Frevert's user avatar
1 vote
Accepted

Bech32 encode/decode library for no_std to convert bytes32 into string address in runtime pallet?

dependency for pallet or any code that compiled to wasm [dependencies] bech32 = { package = "bech32", version = "0.9.1", default-features = false, features = [ "strict", ]...
rust.dev's user avatar
  • 519
1 vote

Calling std-based host function from a pallet

If you have registered the HostFunctions in your host code, you should just include the sp_your_runtime_interface in your pallet to call the host function. Including your std-required crate in pallet ...
Congyu WANG's user avatar
1 vote
Accepted

Calling std-based host function from a pallet

Substrate provide sp-std and sp-io for std calls in a no_std environment. By the error I can understand you are using std instead of sp-std or sp-io so it is giving you the error duplicate lang item ...
Shubham Gupta's user avatar
1 vote

Why `features = ["std"]` is not necessary in the `[dev-dependencies]` some crates like `sp-io`?

I think it's because the frame-system also depends on sp-io. And you enable the std for the frame-system in the test env, which also enables the sp-io/std for the whole scope.
AurevoirXavier's user avatar
  • 10.7k
1 vote

fail to use a no_std friendly dependence in smart contract

This is likely because you are not using the correct features for barebones-x509 in your Cargo.toml. To be sure you would have to post it. I suspect that you are missing something like this: @@ -11,6 +...
cmichi's user avatar
  • 2,800
1 vote

How to set timestamp in benchmarks?

You should use your benchmarking setup to insert a fake timestamp into your runtime, and use that for the execution of your code. Similar to how you would insert fake balances or other storage items ...
Shawn Tabrizi's user avatar
  • 16.1k
1 vote

app_crypto!(sr25519, KEY_TYPE): cannot find trait `TryFrom` in this scope

Have you tried explicetly importing sp_core::Pair as I've mentioned in the answer you linked above?
CREESTL's user avatar
  • 484
1 vote

AssemblyScript Contracts with Javascript Standard Library

There is a project called ask!, which is a domain-specific language for Assembly Script that enables you writing contracts for Substrate's smart contract module ‒ the pallet-contracts. The ask! ...
cmichi's user avatar
  • 2,800
1 vote
Accepted

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

add this line in the local crate at runtime-common/src/lib.rs: #![cfg_attr(not(feature = "std"), no_std)] If you use remote crates, add default-features = false, in your Cargo.toml. For ...
Russo's user avatar
  • 1,193

Only top scored, non community-wiki answers of a minimum length are eligible