sarvalabs / js-moi-sdk

JavaScript library to interact with MOI Protocol via RPC API

Home Page:https://js-moi-sdk.docs.moi.technology/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not allowing user to pick between .call() and .send() when doing routines.endPoint()

Bhimgouda opened this issue · comments

Not allowing user to pick between .call() and .send() when doing routines.endPoint()

Description

Presently, developers have the option to choose between two methods:

routines.SomeEndpoint.call()
// or
routines.SomeEndpoint.send()

This choice may cause confusion, especially for new developers. Additionally, it introduces the risk of developers unintentionally calling a read-only endpoint using .send(), which is not only inefficient (consumes gas and creates a tesseract) but also considered bad practice.

The desired behavior is to have the js-moi-sdk automatically determine the appropriate method based on the nature of the endpoint being called.

Additionally, if a developer intends to simulate interaction with a mutating function, they should continue to use routines.someEndpoint.call() (as per the existing convention).

However, the option of using routines.someEndpoint.send() for this purpose should be deprecated and ultimately removed - The SDK should only decide if the endpoint being called is a mutating function and internally use .send() for such interactions.

Possible resolution

To achieve this behavior, the js-moi-sdk should emulate the pattern used by ethers.js when handling different types of functions:

In case of an error when doing a mutating call: SDK should throw an error.

How ethers handle a mutate function call -

const tx = await erc20Contract.transfer(toAddress, amount);
const receipt = await tx.wait();

How ethers handle a view function call -

const balance = await erc20Contract.balanceOf(targetAddress);

resolved in #36