# leb128\_1.lebEncode issue in react-native

**URL:** <https://forum.dfinity.org/t/leb128-1-lebencode-issue-in-react-native/6023>\
**Category:** Developers\
**Created:** [July 21, 2021, 2:16am UTC](https://forum.dfinity.org/t/leb128-1-lebencode-issue-in-react-native/6023 "2021-07-21T02:16:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ehsan6sha](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/ehsan6sha/32/2460_2.png) [@ehsan6sha](https://forum.dfinity.org/u/ehsan6sha)\
**Post date:** [July 21, 2021, 2:16am UTC](https://forum.dfinity.org/t/leb128-1-lebencode-issue-in-react-native/6023/1 "2021-07-21T02:16:17Z")

</div>

Hi,

There is an issue on react native that using IDL.encode (which is used in creating arg parameter) gets stuck. I narrowed down the problem and it is because of ‘leb128\_1.lebEncode’. I am trying to findout the issue unless someone already knows the answer?

---

<div class="post-metadata">

**Author:** ![ehsan6sha](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/ehsan6sha/32/2460_2.png) [@ehsan6sha](https://forum.dfinity.org/u/ehsan6sha)\
**Post date:** [July 21, 2021, 2:18am UTC](https://forum.dfinity.org/t/leb128-1-lebencode-issue-in-react-native/6023/2 "2021-07-21T02:18:34Z")

</div>

It seems it is stuck in this loop inside function lebEncode:

```auto
while (true) {
        const i = Number(value & BigInt(0x7f));
        value /= BigInt(0x80);
        if (value === BigInt(0)) {
            pipe.write([i]);
            break;
        }
        else {
            pipe.write([i | 0x80]);
        }
    }

```

---

<div class="post-metadata">

**Author:** ![ehsan6sha](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/ehsan6sha/32/2460_2.png) [@ehsan6sha](https://forum.dfinity.org/u/ehsan6sha)\
**Post date:** [July 21, 2021, 3:11am UTC](https://forum.dfinity.org/t/leb128-1-lebencode-issue-in-react-native/6023/3 "2021-07-21T03:11:05Z")

</div>

inside while, BigInt comparison does not work as expected in react native. changin the equality line to below would fix it:

```auto
if (BigInt(0).equals(value)) {

```

---

<div class="post-metadata">

**Author:** ![jzxchiang](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jzxchiang/32/2592_2.png) [@jzxchiang](https://forum.dfinity.org/u/jzxchiang)\
**Post date:** [July 21, 2021, 5:29am UTC](https://forum.dfinity.org/t/leb128-1-lebencode-issue-in-react-native/6023/4 "2021-07-21T05:29:04Z")

</div>

Are you running this in a simulator or on-device? Android or iOS? With a custom JS engine or the default one? With a BigInt polyfill or without?

I’ve been passing BigInts to my canister backend in React Native without problem. I wonder maybe it’s your environment?

---

<div class="post-metadata">

**Author:** ![ehsan6sha](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/ehsan6sha/32/2460_2.png) [@ehsan6sha](https://forum.dfinity.org/u/ehsan6sha)\
**Post date:** [July 21, 2021, 2:58pm UTC](https://forum.dfinity.org/t/leb128-1-lebencode-issue-in-react-native/6023/5 "2021-07-21T14:58:51Z")

</div>

I am running it on Android physical device, with the default engine and with BigInt polyfill. Is this the same environment you ran? From your earlier comments on antoher post I believe you use custom engine ?

---

<div class="post-metadata">

**Author:** ![jzxchiang](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jzxchiang/32/2592_2.png) [@jzxchiang](https://forum.dfinity.org/u/jzxchiang)\
**Post date:** [July 21, 2021, 5:21pm UTC](https://forum.dfinity.org/t/leb128-1-lebencode-issue-in-react-native/6023/6 "2021-07-21T17:21:50Z")

</div>

Ah yeah, I’m using a custom v8 engine. I tried a bunch of BigInt polyfills and they were way too slow. The only one that was fast enough was [JSBI](https://github.com/GoogleChromeLabs/jsbi), but it requires some pretty hefty syntax changes, so I ended up going with v8 instead. Which polyfill are you using?

---

<div class="post-metadata">

**Author:** ![ehsan6sha](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/ehsan6sha/32/2460_2.png) [@ehsan6sha](https://forum.dfinity.org/u/ehsan6sha)\
**Post date:** [July 21, 2021, 5:35pm UTC](https://forum.dfinity.org/t/leb128-1-lebencode-issue-in-react-native/6023/7 "2021-07-21T17:35:07Z")

</div>

I am using ‘big-integer’. any insights on the speed of this?  
[big-integer - npm (npmjs.com)](https://www.npmjs.com/package/big-integer?activeTab=versions)

---

<div class="post-metadata">

**Author:** ![jzxchiang](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jzxchiang/32/2592_2.png) [@jzxchiang](https://forum.dfinity.org/u/jzxchiang)\
**Post date:** [July 21, 2021, 11:21pm UTC](https://forum.dfinity.org/t/leb128-1-lebencode-issue-in-react-native/6023/8 "2021-07-21T23:21:21Z")

</div>

Yeah, I don’t think this one worked for me. I forgot it it was due to an error or performance.
