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

One endpoint to get AE token transfers filtered by contractId and accountId #1678

Open
peronczyk opened this issue Feb 8, 2024 · 13 comments
Assignees

Comments

@peronczyk
Copy link

Hi. This entry is a follow up to this issue: #1580

Currently the @aeternity/superhero team is working on handling not only AE protocol, but also Bitcoin and Ethereum. This requires us to avoid hacks and protocol specific workarounds so the wallet is as plugabble as it can be.

As @CedrikNikita mentioned in his comment (#1580 (comment)) having two separate endpoints for sender and receiver is not usable for us. We are not able to keep two separate next page urls when trying to obtain one list. It would be possible if our wallet would be focused on AE protocol only, but we need to keep a lot of data and splitting the calls makes our work insanely hard. Please see for example how Etherscan is handling this: https://docs.etherscan.io/api-endpoints/accounts#get-a-list-of-erc20-token-transfer-events-by-address - if we provide the contractaddress param we receive the list of all transactions for this particular token.

So maybe there is a possibility of having one endpoint for fetching all token transactions?

@peronczyk peronczyk changed the title One endpoint to get AE token transfers filtered by contractId and accountId One endpoint to get AE token transfers filtered by contractId and accountId Feb 8, 2024
@peronczyk
Copy link
Author

We have this endpoint https://testnet.aeternity.io/mdw/v2/txs?account=<AccountAddress>&contract=<TokenContractAddress> but it only returns the transactions created by the account. Maybe we could use it and include incoming transactions there?

@sborrazas
Copy link
Contributor

We have this endpoint https://testnet.aeternity.io/mdw/v2/txs?account=<AccountAddress>&contract=<TokenContractAddress> but it only returns the transactions created by the account. Maybe we could use it and include incoming transactions there?

The /v2/txs endpoint, when filtering by account, will show up any account that appears in the transaction fields. For example, this URL https://testnet.aeternity.io/mdw/v2/txs?account=ak_dgu9HWMMGjWtX8p9YD3rKpXKstrXQn6iQU8fKgivz66mZC3CE is going to filter everywhere where the account ak_dgu9HWMMGjWtX8p9YD3rKpXKstrXQn6iQU8fKgivz66mZC3CE is present, which includes the contract create transsaction for this contract and all subsequent contract calls.

@sborrazas
Copy link
Contributor

@CedrikNikita the /txs/ endpoint filters does not do any interpretation of the contract calls. contract calls have only two field that reference an address: the caller it and the contract id, these are the only two thing that you can filter by when using /txs?account=...

@smaroudasunicorn
Copy link

Hello, we would like to request an endpoint that returns all transactions (incoming/outgoing) in a list for an account and a desired token. Is there one provided (or to be implemented) that can fulfil our need for SH Wallet?

Thanks

@peronczyk
Copy link
Author

peronczyk commented Feb 9, 2024

@CedrikNikita the /txs/ endpoint filters does not do any interpretation of the contract calls. contract calls have only two field that reference an address: the caller it and the contract id, these are the only two thing that you can filter by when using /txs?account=...

@sborrazas If you are not able to update the /txs endpoint new one can be created. It's your decision.

Right now the wallet team can choose between these 3 options:

  1. /txs - not usable because it's not providing incoming transactions for tokens, only outgoing
  2. /activities - we are using this one and filtering out the transactions that doesn't match the contractId of the token. But this is bad because sometimes there is no token transaction on the first page and we are not able to establish if there's really next page for the token. Also the need of fetching too much data is rather bad.
  3. /aex9 - not usable for us because of the need of using two separate calls to have full list of incoming and outgoing transactions.

Edit:
Maybe the activities/ endpoint could have additional param so the results would be narrowed to selected token. Even better if we could use this endpoint to get only the activities for the AE Coin only.

Here are the screens from our app to visualise where exactly we need the new endpoint.

  1. Account details (/activities endpoint works nice here as we are displaying all activities for the account):
image
  1. Account Details / Coin (would be nice to have endpoint that returns the activities for the account/coin):
image
  1. Account Details / Token (this needs new API enpoint):
image

@sborrazas
Copy link
Contributor

@peronczyk

Thanks for explaining it further. This is my interpretation of these endpoints:

  • /txs indeed only displays outgoing tokens because it's filtering contract call transactions made by (caller_id) the account being filtered by. This is direct field of the transaction and has no relation to the token or AEx9, because it doesn't interpret the contract call at all.
  • /activities lets you filter activities by a single account, e.g. transactions made by that account, aex9 transfers where that account is involved. But it won't let you filter by TWO accounts (e.g. contract account and token holder account), or THREE accounts. This endpoint is not meant for that.
  • /aex9 transfers endpoint is indeed intended to return aex9 transfer and balances, but right now you can only retrieve all of the transfers for a given contract (token) for a given sender or recipient, not both. This is the endpoint that would make sense to have a filter /aex9/:contract_id/balances?account=ak_... or /aex9/:contract_id/balances?account=ak_... where the account can be any of the recipient or sender of the aex9 tokens.

This last alternative is what we can implement next.

@CedrikNikita
Copy link

This last alternative is what initial issue was about. We were asking exactly that behaviour. To get all specific contract related transactions for an account with one call.

@peronczyk
Copy link
Author

@sborrazas yes, your summary gets to the heart of the problem. And I agree with you and Nikita that the 3rd option would probably be the best one. I only don't understand why there is /balances in the address. At the end we don't really care what would be the address :) We only need transaction list. In my opinion the best inspiration is the Etherscan tokentx endpoint: https://docs.etherscan.io/api-endpoints/accounts#get-a-list-of-erc20-token-transfer-events-by-address

@peronczyk
Copy link
Author

peronczyk commented Mar 8, 2024

Hi. Did you make any progress with this topic?
@sborrazas

@sborrazas sborrazas self-assigned this Mar 20, 2024
@sborrazas
Copy link
Contributor

Hi. Did you make any progress with this topic? @sborrazas

I just checked the AEx9 transfers endpoint and you can actually get the transfers (both as sender OR receiver) using the account=ak_.. query parameter, like so:
https://testnet.aeternity.io/mdw/v3/aex9/ct_NH6qfe8Gu5QdX7fdmdyD5iQ5yHC64FE4ELsMUok4VWDuqBkct/transfers?account=ak_2AVeRypSdS4ZosdKWW1C4avWU4eeC2Yq7oP7guBGy8jkxdYVUy

This way you don't need to make 2 requests to get the transfers as sender sender=ak_... and a different one for recipient recipient=ak_...

@peronczyk
Copy link
Author

Thank you @sborrazas for your research. We'll test this and come back with the results.

@sborrazas
Copy link
Contributor

@peronczyk any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants