js-algorand-sdk
js-algorand-sdk copied to clipboard
Why the `args` of transaction constructor are strictly required to be `UInt8Array`?
I noticed the following code in the transaction constructor:
txn.appArgs.forEach((arg) => {
if (arg.constructor !== Uint8Array)
throw Error('each element of AppArgs must be a Uint8Array.');
});
It forces the args to be of type Uint8Array
, but ignores the inheritance tree. I stumbled upon this when tried to pass Buffer
as transaction args, but received this error. My question is: is it intentional to force args to be strictly UInt8Array
? Because I'd suggest to use instanceof
here if it won't break anything.
@jasonpaulos do you know why this is?
I believe this is because Uint8Array
and Buffer
have some differences, and we like to maintain consistency internally.
That being said, I think it'd be reasonable for the constructor to convert any Buffer
arguments to Uint8Array
s instead of erroring.