web3swift-team / web3swift

Elegant Web3js functionality in Swift. Native ABI parsing and smart contract interactions.
Apache License 2.0
818 stars 441 forks source link

How to get my wallet's transaction history list, gas price and token 's detail? #377

Closed JJBFC closed 2 years ago

JJBFC commented 3 years ago

Hi all, I m working on a wallet project, and found some problem that I can't handle with web3swift doc. I can get transID after each transaction, but how to get my wallet's transaction history list? Almost every dapp will show gasprice with high, average and slow speed when prepare to send a transaction. Where can I get the gas price? How to get unit price, symbol name and icon for a token? Btw, where do you guys get monetary exchange rate?

JJBFC commented 3 years ago

I 've read all functions in Web3+Eth.swift, looks like there 's no function that satisfied my needs. And I also confused with :let block = try! web3.eth.getBlockByNumber(blockNumber, fullTransactions: false) let transactionInBlockArr : [TransactionInBlock] = block.transactions let transactionInBlock : TransactionInBlock = transactionInBlockArr.first! What exactly mean for block.transactions? Is it transaction records for the block?

JJBFC commented 3 years ago

@skywinder Pls help me boss~!

dangell7 commented 3 years ago

You have to cycle through all transactions.

  1. Get list of tx hash's
  2. For each
dangell7 commented 3 years ago

Gas price is web3.eth.gasPrice I believe. Exchange rate is your choice, I use kucoin api and update my own database. Token details are called through call transactions

JJBFC commented 3 years ago

@dangell7 Thanks so much for reply me! How can I get tx hashs with my address and the token address, still not found it.. For web3.eth.gasPrice only return one price, so how can I calculate the high speed price and slow speed price? For token details, I need to show the token unit price before transactions even in my homepage, what should I do. If you can show me the code that would be great! Thanks bro!

JJBFC commented 3 years ago

@dangell7 I can get tx hash after finishing a transaction. So how can I get tx's hash list when I import a wallet without doing transations which almost every dapp can do?

dangell7 commented 3 years ago

I do the transaction sync on the server. I use filters and cycle through the blocks. I think there is even a GitHub repo if you search. I went the long way though. Here is the docs for web3 python Learn More.

Gas Price is just an estimate. Its an arbitrary number. In the beginning there was no high or slow. It was one number and we started just "estimating". There are some calculators out there. You could use python web3 I know they return the prices. Or there's likely another api.

And I use the kucoin api for prices. Learn More

JJBFC commented 3 years ago

Hi @dangell7 , I tried some api from Infura. eth_getTransactionCount should return the count that my wallet made, but only the count. eth_getTransactionByHash should return the whole detail for one tx. I tried to combine this two method to get my history list but still not found how to get every hash for my tx. The getLogs api looks like can show the whole logs with my wallet address, but I don't really know how to set the "fromBlock" and "toBlock". What a day : (

jesuasir007 commented 3 years ago

@dangell7 Thanks so much for reply me! How can I get tx hashs with my address and the token address, still not found it.. For web3.eth.gasPrice only return one price, so how can I calculate the high speed price and slow speed price? For token details, I need to show the token unit price before transactions even in my homepage, what should I do. If you can show me the code that would be great! Thanks bro!

hi please show some example for calculate slow medium and fast gas fees estimation any one help about this topic ?

SheepP commented 2 years ago

Oops, I also meet the same issue, have any progress?

Nahatakyan commented 2 years ago

I have the same issue

yaroslavyaroslav commented 2 years ago

Please see #576 issue. Spoiler: you're too use some external services for both tasks.