vechain-sdk-js icon indicating copy to clipboard operation
vechain-sdk-js copied to clipboard

💡 [REQUEST] - Return value from Contract.reads instead of lists

Open ifavo opened this issue 6 months ago • 0 comments

Summary

When reading from a contract using a Contract instance from sdk-network, the result is always returned as a list. (This appears to be due to the raw ThorNode results being passed through, which return lists because of multi-clause processing.)

From a developer experience standpoint, this consistent use of lists adds unnecessary complexity and friction during development.

To enhance the developer experience, I suggest modifying the function to return the value of [0] directly in such cases, rather than leaving it in a list.

Basic Example

const VTHO = new Contract("0x...", [...ABI_ERC20], thorClient)

// current situation
const [balance] = await VTHO.read.balanceOf(address)

// desired situation
const balance = await VTHO.read.balanceOf(address)

ifavo avatar Aug 14 '24 04:08 ifavo