CRYPTO NEWS

Conversion from Wei to Ether gives different results

I’m trying to analyze the transaction of this contract, but sometimes when I try to convert from wei to ether value of tokens I got comma in different position than expected. This is how I proceed:

1)Fetch all transactions from Moralis API.
2)Take the ABI of the contract, and from the tx_input I decode the transaction in this way:

contract = web3.eth.contract(address=Web3.toChecksumAddress(tx["to_address"]), abi=abi['result']) func_obj, func_params = contract.decode_function_input(tx["input"]) 
  1. I get the wei value of token sent to the contract selecting the func_params with the following path func_params['amountsInOutMarketMaxFee'][0] in the case of Swap Function invoked.

Everything is fine unless in some case when I try to convert some numbers from wei to ether value I got different numbers than seen in explorers. For example when I fetch the following transaction from the contract above: https://polygonscan.com/tx/0xa2d59655b42f947dc619f456553476f7b5929ef1ec6da229409dde9d6fb9629d I got the following value:

13045952229932174800 

That’s the same amount you get from the decoded input in the blockchain explorer page. But if I try to convert the amount with the following function:

 Web3.fromWei(tx_data['amountsInOutMaxFee'][0], 'ether') 

I got 13.04 while on the blockchain explorer the amount is 1.304 Why is there this lack? Thank you for the answers.

Best way to track the history of tokens

I want to create a dApp that can track the history of tokens (specifically ETH as of now) and store a status with them. It needs to be able to get the history of tokens that belong to an address. I know that ETH is fungible, but I have a few algorithms for deciding which::Listen

I want to create a dApp that can track the history of tokens (specifically ETH as of now) and store a status with them.

It needs to be able to get the history of tokens that belong to an address.

I know that ETH is fungible, but I have a few algorithms for deciding which tokens go where and which ones are transferred: https://twitter.com/mteamisloading/status/1543077072750268418?s=20&t=grrToJKuFNWwlyhmdOmY4Q

So my question: how can I get the ending address of a token given a starting address?

It needs to make a sort of tree: following through transactions to other accounts, check all of their transactions to see if the token would be sent (according to one of the aforementioned algorithms) and so on. Apparently this is really hard to do! I have seen this:

https://stackoverflow.com/questions/36291117/how-to-get-ethereum-transaction-list-by-address

and there seems to be trouble with making many requests.

Another option is using an indexer like https://github.com/getamis/eth-indexer, but it requires massive amounts of storage (that I don’t have) and seems like a clunky solution, because I only need a few specific transactions.

Event logs won’t work because they only log for smart contract interactions.

Maybe https://docs.alchemy.com/alchemy/enhanced-apis/transfers-api ?

Is there an API already? How can I do this?

Conversion from Wei to Ether gives different results

Shopping cart
There are no products in the cart!
Continue shopping
0