question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Derived TypedArray constructor created an array which was too small

See original GitHub issue

When reading a vector (contains a little over 100 u64 elements) from a smart contract, API throws the error below. Ping me if you need the contract code, binaries, and full JS code.

API version: 2.8.1

SC Method definition:

pub fn get(&self) -> Vec<u64>

JS Code:

async function readContract(api, sender) {
  const abi = new Abi(contractAbi);
  const contract = new ContractPromise(api, abi, config.contractAddress);

  const vec = await contract.query.get(sender.address, value, maxgas);
  console.log("Vector read. Length: ", vec.output.length);
}

Error:

2020-11-27 17:30:03        REGISTRY: TypeError: Derived TypedArray constructor created an array which was too small
    at Bytes.slice (<anonymous>)
    at compactFromU8a (/home/greg/Development/src/polkadot/nft/smart_contracts/load_test_scripts/node_modules/@polkadot/util/compact/fromU8a.js:41:40)
    at Function.decodeVec (/home/greg/Development/src/polkadot/nft/smart_contracts/load_test_scripts/node_modules/@polkadot/api-contract/node_modules/@polkadot/types/codec/Vec.js:50:55)
    at new Vec (/home/greg/Development/src/polkadot/nft/smart_contracts/load_test_scripts/node_modules/@polkadot/api-contract/node_modules/@polkadot/types/codec/Vec.js:29:28)
    at new <anonymous> (/home/greg/Development/src/polkadot/nft/smart_contracts/load_test_scripts/node_modules/@polkadot/api-contract/node_modules/@polkadot/types/codec/Vec.js:58:9)
    at initType (/home/greg/Development/src/polkadot/nft/smart_contracts/load_test_scripts/node_modules/@polkadot/api-contract/node_modules/@polkadot/types/create/createType.js:49:19)
    at createTypeUnsafe (/home/greg/Development/src/polkadot/nft/smart_contracts/load_test_scripts/node_modules/@polkadot/api-contract/node_modules/@polkadot/types/create/createType.js:68:12)
    at formatData (/home/greg/Development/src/polkadot/nft/smart_contracts/load_test_scripts/node_modules/@polkadot/api-contract/util.js:20:39)
    at MapSubscriber.project (/home/greg/Development/src/polkadot/nft/smart_contracts/load_test_scripts/node_modules/@polkadot/api-contract/base/Contract.js:177:81)
    at MapSubscriber._next (/home/greg/Development/src/polkadot/nft/smart_contracts/load_test_scripts/node_modules/rxjs/internal/operators/map.js:49:35)
Error: createType(Vec<u64>):: Derived TypedArray constructor created an array which was too small
    at createTypeUnsafe (/home/greg/Development/src/polkadot/nft/smart_contracts/load_test_scripts/node_modules/@polkadot/api-contract/node_modules/@polkadot/types/create/createType.js:71:11)
    at formatData (/home/greg/Development/src/polkadot/nft/smart_contracts/load_test_scripts/node_modules/@polkadot/api-contract/util.js:20:39)
    at MapSubscriber.project (/home/greg/Development/src/polkadot/nft/smart_contracts/load_test_scripts/node_modules/@polkadot/api-contract/base/Contract.js:177:81)
    at MapSubscriber._next (/home/greg/Development/src/polkadot/nft/smart_contracts/load_test_scripts/node_modules/rxjs/internal/operators/map.js:49:35)
    at MapSubscriber.Subscriber.next (/home/greg/Development/src/polkadot/nft/smart_contracts/load_test_scripts/node_modules/rxjs/internal/Subscriber.js:66:18)
    at RefCountSubscriber.Subscriber._next (/home/greg/Development/src/polkadot/nft/smart_contracts/load_test_scripts/node_modules/rxjs/internal/Subscriber.js:89:26)
    at RefCountSubscriber.Subscriber.next (/home/greg/Development/src/polkadot/nft/smart_contracts/load_test_scripts/node_modules/rxjs/internal/Subscriber.js:66:18)
    at ReplaySubject.Subject.next (/home/greg/Development/src/polkadot/nft/smart_contracts/load_test_scripts/node_modules/rxjs/internal/Subject.js:60:25)
    at ReplaySubject.nextInfiniteTimeWindow (/home/greg/Development/src/polkadot/nft/smart_contracts/load_test_scripts/node_modules/rxjs/internal/ReplaySubject.js:50:31)
    at ConnectableSubscriber.Subscriber._next (/home/greg/Development/src/polkadot/nft/smart_contracts/load_test_scripts/node_modules/rxjs/internal/Subscriber.js:89:26)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
gregzaitsevcommented, Nov 27, 2020

Sure! Call bloat(100) to populate the contract’s returned vector with 100 values.

loadtester.tar.gz

0reactions
polkadot-js-botcommented, Jun 3, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Derived TypedArray constructor created an array which was ...
The new Decorated func throws an error createType(StorageKey):: Derived TypedArray constructor created an array which was too small on RN ...
Read more >
20. Typed Arrays - Exploring JS
ArrayBuffers store the data, views (Typed Arrays and DataViews) let you read and change it. In order to create a DataView, you need...
Read more >
Error Connecting to Substrate: Unable to initialize the API
Anyway, I bound the @polkadot/api to my node via the command: ... Derived TypedArray constructor created an array which was too small.
Read more >
TypedArray - JavaScript - MDN Web Docs
The constructor function used to create derived objects. All TypedArray subclasses also have the following static properties: TypedArray.
Read more >
src/messages.h - v8/v8 - Git at Google
"Function.prototype.apply was called on %, which is a % and not a " \ ... "Derived ArrayBuffer constructor created a buffer which was...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found