Skip to main content
11 votes

How to get the balance of an account at a particular nonce using Polkadot.js API

You can get the balance of an account at any given block hash. For example: const { nonce, data: balance } = await api.query.system.account.at(HASH, ADDR); Or, alternatively, you can create a new ...
kianenigma's user avatar
  • 2,799
7 votes
Accepted

How to use the polkadot/dev project template

The polkadot-js dev repo is not a template project for helping with using the @polkadot/* libs, rather it is a set of templates, configs and scripts that helps all the polkadot-js repos to be ...
Jaco's user avatar
  • 5,865
5 votes
Accepted

How to change input from string to Id::Bytes in JavaScript?

For any enum, the input is index + bytes. So depending on the enum, the first byte needs to be the actual enum id or (in the case of the JS API) identify the enum, type. Since you have no info, some ...
Jaco's user avatar
  • 5,865
5 votes

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

Here's an example of how I managed to get this information using the @polkadot JavaScript libraries. Import the Polkadot JS libraries yarn add @polkadot/api @polkadot/util var { ApiPromise, ...
Rtsne42's user avatar
  • 379
4 votes
Accepted

OutOfGas Error when trying to read contract data using Polkadot JS API

The error is telling you that the gas limit you have provided is too low. You supplied a limit of 3 * 10^9 which is 3 milliseconds of execution (1 gas = 1 pico second). This could be too less if the ...
Alexander Theißen's user avatar
4 votes

Access your NFTs using PolkadotJS API

If you want to gain Access to NFTs which you purchased on Singular, then you are dealing with RMRK NFTs which live in Smart Contracts deployed to the Moonriver Network which is a L1 parachchain on ...
Achim's user avatar
  • 575
3 votes
Accepted

Create hex encoded call (for XCM transact call) in javascript?

When you construct via api.tx.* is creates an unsigned extrinsic. So basically you want the call-only part of that. // output as hex const encoded = u8aToHex( // add length to the U8a (double-...
Jaco's user avatar
  • 5,865
3 votes

How to get raw payload from Polkadot JS transaction

Solution: The payload needs to be populated and formatted manually. Here is a complete example: Notes: era is immortal, meaning the tx will always be valid. method just requires a Call type of your ...
Ross's user avatar
  • 171
3 votes

How to use smoldot in rust application?

If you look at the basic example you can see how to initialize a Smoldot client. Provide the chainspec of the chain you want to sync with and make JSON-RPC requests. But I agree, a native rust ...
Daan van der Plas's user avatar
3 votes
Accepted

Substrate-Connect Error on new ScProvider

You need at least the SubstrateConnect instance (And the relay chain in case of a parachain). See the example to connect to Statemint: import { ScProvider} from "@polkadot/rpc-provider"; ...
Alex Bean's user avatar
  • 5,757
3 votes
Accepted

Question for api.call.transactionPaymentApi.queryInfo state call

Correct. The encoded length of the extrinsic (ref). Why is the len parameter required? The runtime doesn't know all the decoding context of the the encoded call (ref). So you can't just pass the ...
Daan van der Plas's user avatar
3 votes
Accepted

Embedding javascript (wasm) in substrate runtime

I don't think that compiling JS to wasm is possible currently. Effective compilation requires GC at least, and that Wasm extension proposal is still under development. It's also not clear if a ...
pepyakin's user avatar
  • 2,184
3 votes

How to create a tuple type using polkadot.js api

Tuple types are specified in the same way they are in Rust, i.e. (AccountId, u32) will yield a tuple with AccountId and u32. These are all string values, i.e. MyTuple: "(AccountId, u32)", ...
Barto's user avatar
  • 584
3 votes

How to signAndSend() without a MNEMONIC

To integrate with the extension, see this usage info as well as a slightly different sample in the cookbook. Basically you get a list of accounts from the extension and then attach a signer, from the ...
Jaco's user avatar
  • 5,865
2 votes

Error encountered could not complete yarn install of substrate front end template

Resolved it by performing these steps yarn cache clean --all yarn install At this point, got the same error. Then run this: YARN_CHECKSUM_BEHAVIOR=update yarn Credits to answer from Github ...
John's user avatar
  • 121
2 votes
Accepted

Invalid params: unknown field `storageDepositLimit` Error when getting contract data from a chain

I found the reason: Compatibility issue. The testnet I was trying to connect to used an older version of substrate.
Minh Mốc's user avatar
  • 1,009
2 votes

How can I listen to new receive transfer?

I would suggest splitting your questions into two - it is somewhat difficult to answer 2 completely different questions coherently in one. First off, you mention "hash" - be aware that ...
Barto's user avatar
  • 584
2 votes

Access your NFTs using PolkadotJS API

So, thanks to Achim, in the rmrk-tools repo, you can use: https://github.com/rmrk-team/rmrk-tools#fetchremarks fetchRemarks(api, to, from, prefixes); method call It's not pretty but it's a start: ...
rarara's user avatar
  • 141
2 votes

Get remaining value of bounty after child bounty

When a child bounty is created, the amount is already deducted for it from the parent bounty's balance. At any time, the parent bounty's balance would show only the remaining amount for any new child ...
Gautam D's user avatar
2 votes

How to handle XCM encoding and building in JavaScript

XCM messages are simply SCALE-encoded according to their specification. SCALE is a binary encoding format which is described here: https://docs.substrate.io/reference/scale-codec/ You can use the ...
rob's user avatar
  • 2,126
2 votes

Invalid Transaction: Transaction has a bad signature - Ledger signature into tx

Solution Detailed explanations of the problem and great troubleshooting pointers can be found on the JS Apps issue here: https://github.com/polkadot-js/api/issues/5555 To summarise, ensure the entire ...
Ross's user avatar
  • 171
2 votes

How to pass value as a argument in send transactions?

I doesn't seem that the error is a chain related. It will behave the same on any other parachain. You need to provide origin (caller address) to the call. const { gasRequired, result } = await ...
Bobo K.'s user avatar
  • 386
1 vote

How to verify that signed transaction, is correctly signed?

As Jaco explained in this GitHub issue, you can't just verify the signature of a transaction with polkadot.js. Alex's answer is a good alternative by using the tool Subkey. However, if instead of ...
Iker's user avatar
  • 1,356
1 vote

How to verify that signed transaction, is correctly signed?

Do you need to do it in PolkadotJS? Otherwise you can use the tool Subkey: https://docs.substrate.io/reference/command-line-tools/subkey/ with the command: subkey verify <your-signedTxHex> <...
Alex Bean's user avatar
  • 5,757
1 vote
Accepted

How can you query a smart contract using the polkadot.js api?

Following the Polkadot JS docs, I don't see where wasm is used tbh import { ContractPromise } from '@polkadot/api-contract'; // The address is the actual on-chain address as ss58 or AccountId object. ...
andresvsm's user avatar
  • 1,114
1 vote

How to retrive data stored in a block

With your instruction const signedBlock = await api.rpc.chain.getBlock(blockHash); You have all the information on the Block, you can get now all the extrinsics from the block signedBlock.block....
Alex Bean's user avatar
  • 5,757
1 vote

JavaScript/TypeScript: How to pass arguments of an array individually to a function?

An option to do this is using apply. The code would look like this: const { gasRequired, storageDeposit, result, output } = await contract.query[message].apply(null, [ accountId, { ...
rajohs's user avatar
  • 491
1 vote
Accepted

Run JavaScript Js scripts in Zombienet tests and assert on the completeness or return value

thanks for your feedback! The custom js script must export a function call run that zombienet will call as part of the assertion. You can check as example https://github.com/paritytech/zombienet/blob/...
pepoviola's user avatar
  • 792
1 vote

Are there any tools available for creating a mock version of a contract in JS/TS?

In order to do an integration test you would need to spawn a substrate-contracts-node and then use the polkadot.js javscript library in order to interact with it. Another way would be to use the cargo-...
Alexander Theißen's user avatar
1 vote

Dev Substrate Node at Capacity for WS Connections, how to flush?

As @Shawn mentioned you can try --ws-max-out-buffer-capacity=99999 That worked for us Also, I confirmed that the ws connection disconnects at either refresh or if you navigate away from the tab You ...
Sam Elamin's user avatar
  • 1,223

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