Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] New API to Atomize Operations #8

Open
songkeys opened this issue Mar 3, 2023 · 2 comments
Open

[Proposal] New API to Atomize Operations #8

songkeys opened this issue Mar 3, 2023 · 2 comments
Assignees
Labels
proposal Proposal

Comments

@songkeys
Copy link
Member

songkeys commented Mar 3, 2023

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?

@songkeys songkeys added the proposal Proposal label Mar 13, 2023
@songkeys songkeys added this to the 1.0 milestone Mar 13, 2023
@songkeys songkeys added the v1 label Mar 13, 2023
@sxzz
Copy link
Contributor

sxzz commented Apr 14, 2023

I think we can omit the send function.

const txPromise = await contract.note.post(...)
const data = await txPromise.data() // waits the transaction to be mined and returns data

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

@sxzz sxzz self-assigned this Apr 18, 2023
@sxzz
Copy link
Contributor

sxzz commented May 12, 2023

image

We should wait ERC-4337 to be supported in viem.

Reference

@sxzz sxzz removed this from the 1.0 milestone May 12, 2023
@sxzz sxzz removed the v1 label May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Proposal
Projects
None yet
Development

No branches or pull requests

2 participants