Skip to content

[Proposal] New API to Atomize Operations #8

@songkeys

Description

@songkeys

Background

The current API is designed to only care for sending a transaction and waiting it to be mined. E.g.,

const data = await contract.postNote(...)

When this promise resolves, it means the transaction has been sent and mined.

This makes the following situation hard to handle:

  1. The app only needs to know that a transaction has been sent. For example, the app wants to distinguish the two steps so as to show the loading prompt as "Sending" and "Mining".
  2. The app wants to do multicall which involves in multiple contract function getting encoded, sent, and mined.

Proposal

Chain methods are adopted to the new API. The new methods are:

  • .send()
  • .data()
  • anything else?

The new API will go like this:

const fn = await contract.postNote(...) // only encodes the contract function
const tx = await fn.send() // sends transaction
const data = await tx.data() // waits the transaction to be mined and returns data

// or in chain
const data = await contract.postNote().send().data()

If the app wants to do multicall:

const fns = [contract.postNote(...), contract.postNote(...), contract.postNote(...)]
const multicallFn = await contract.multicall(fns).send().data()

Let me know what you think?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions