starknet.js icon indicating copy to clipboard operation
starknet.js copied to clipboard

Better way to parse Uint256 result of `Args` to BN

Open dhruvkelawala opened this issue 2 years ago • 1 comments

Currently,

export type Args = { [inputName: string]: string | string[] | { type: 'struct'; [k: string]: BigNumberish }; };

The type of Args does not include a type Uint256 which is a normal JS object with low and high properties. How should it be parsed on frontend?

For example,

Example ABI: { "inputs": [ { "name": "account", "type": "felt" } ], "name": "balanceOf", "outputs": [ { "name": "balance", "type": "Uint256" } ], "stateMutability": "view", "type": "function" }

The output of balanceOf call will be of type Args

const result = contract.call(balanceOf, { account: address }) // returns result = { balance: Object }

Here, the type of balance is neither string, string[] or struct.

Type string | string[] | { type: 'struct'; [k: string]: BigNumberish is also not compatible with arguement of uint256ToBN().

Currently, I am passing result as any in uint256ToBN which is not a good way to do this.

dhruvkelawala avatar Jan 12 '22 17:01 dhruvkelawala

@dhruvkelawala hi! Is this issue still relevant?

ivpavici avatar Aug 12 '22 13:08 ivpavici

What is the meaning of low and higt?How should it be parsed on frontend? @ivpavici

YaminZheng avatar Oct 12 '23 08:10 YaminZheng