vechain / thor-devkit.js

Typescript library to aid DApp development on VeChain Thor
MIT License
38 stars 30 forks source link

handle large value in clause #20

Closed simonzg closed 4 years ago

simonzg commented 4 years ago

Hi, thank you for your work on this helpful library, I've been using it for a while now and so far so good. Except for one thing that I noticed:

if I set a large number in the value field of a clause like this:

let clauses = [
  {
    to: '0x7567d83b7b8d80addcb281a71d54fc7b3364ffed',
    value: 1e18, // HERE
    data: '0x'
  }
];

Then errors show up

/tmp/node_modules/thor-devkit/dist/rlp.js:222
        throw new RLPError(`${ctx}: ${msg}`);
        ^

RLPError: tx.clauses.#0.value: expected non-negative safe integer
    at assert (/tmp/node_modules/thor-devkit/dist/rlp.js:222:15)
    at NumericKind.data (/tmp/node_modules/thor-devkit/dist/rlp.js:64:17)
    at pack (/tmp/node_modules/thor-devkit/dist/rlp.js:191:21)
    at kind.map.k (/tmp/node_modules/thor-devkit/dist/rlp.js:194:30)
    at Array.map (<anonymous>)
    at pack (/tmp/node_modules/thor-devkit/dist/rlp.js:194:21)
    at obj.map (/tmp/node_modules/thor-devkit/dist/rlp.js:198:33)
    at Array.map (<anonymous>)
    at pack (/tmp/node_modules/thor-devkit/dist/rlp.js:198:16)
    at kind.map.k (/tmp/node_modules/thor-devkit/dist/rlp.js:194:30)

but if I set the value less than 1e15, it works. I understand this is due to typescript's definition of the largest number (2^53-1), however, it's quite annoying if I can't build a transfer with more than one coin. Any suggestions or workaround? Thank you.

simonzg commented 4 years ago

I just figured out myself. put string instead of number would do the trick. Close the issue right now.