How to tell if an ERC20 token transfer succeeded? - ethereum

I've cobbled together some code to send some tokens using web3.js 1.0.0-beta46 and then decided to try to send more token than I had in my wallet. to my great surprise the transaction send succeeded and I got a txid, but of course the transfer failed
here's the attempt (on Ropsten):
https://ropsten.etherscan.io/tx/0xaf2708dcc9b86b7cca0076e329a1e81fc28fdc4a97765b0a79544ec0685cfa69
now my question: how can I tell when the transfer succeeded? or for that matter how can I get the error message? etherscan merely indicates:
ERC-20 Token Transfer Error (Unable to locate Corresponding Transfer Event Logs), Check with Sender

The most simple and straightforward way would be to check the balances of sender and receiver before and after the transfer.
Now about the failed transfer, after reading the contract I noticed that in the event of insufficient funds you simple return false, which makes a valid transaction. What you should do is revert the transactions using require to make the checks. That way an invalid transaction will be reverted by the EVM which will be recognized by etherscan and show that the transaction failed.

Related

Track smart contract transactions

I am searching for an efficient way to track contract transactions.
Specifically, I want to receive an immediate notification when a specific function with a specific parameter is executed.
Any ideas or suggestions?
The most efficient approach is to listen for new blocks and fetch every transaction from the block via GraphQL (I assume you use geth) which then gives you the block header, transaction and transaction receipt in a single http call.
From there you can ABI decode any transaction input which matches your function signature to obtain the function parameters and join that with the tx status from the receipt.
I am personally writing a similar component (https://github.com/grassrootseconomics/cic-chain-events/) to track ERC20 transfers and notify users (SMS, Telegram, e.t.c). You can borrow and extend concepts from it.
Run your own node
Subscribe to WebSocket hook to receive a notification for every transaction
Check if the transaction matches your parameters
if within your smart contract function there are events emitted with the inputs that your user provide, then it will be possible to listen to those events (and thus your function call) and the corresponding transaction in real-time with Moralis Streams API.
Essentially to work with this, you will need a webhook where Moralis will be able to stream those events and transaction data constantly. To test it out really quickly, you can use https://webhook.site as a test webhook.
To get started with Streams API, you can follow this tutorial right here https://docs.moralis.io/streams-api/getting-started
Hope this helps!

Detect ETH transfer which made by smart contract

I need to analyze blocks and txs to find if there is a transfer ETH to address from my list. When some user makes a direct transfer it is clear, I can check to parameter of the transaction. But sometimes users execute smart contracts which transfer ETH to address from my list, in this case to is the address of the smart contract, so I can't match it with my list. Is there a way to handle such cases?
If you mean something like an "internal tx" of a forwarding contract like this example. Which does a value call (address.call()()). Then there is no way of knowing the final destination with tracing the transaction. Alternatively some contracts could emit an event or in the case of forwarding contracts, you could read the 'parentAddress' set during contract init.
Etherscan parses the trace for you so you can see those internal transfers afaik (see example above).

How use walletconnect for tokens transaction

I'm using wallet connect for Eth transaction in my app.
but now need transact an ERC-20 token and don't know how do that
It has passed 8 months, but I'll answer.
You need to first approve on the sender side and do the transaction later. WalletConnect only uses Mainnet, so test it using https://test.walletconnect.org/ or first work on the Metamask testnets and apply to Walletconnect

Transaction showing on etherscan.io but no showing on API.etherscan

I am trying to get the transactions of an address using
https://api.etherscan.io/api?module=account&action=txlist&address=0x9bb1499d06f3036a12f653f00b889731d04c47a0&startblock=0&endblock=92649034&sort=asc&apikey=XXXXX
however, I get the results "No transactions found" when in fact, a transaction exists, and can be viewed on etherscan.io site.
I wonder if anyone has encountered the same problem. Is this a bug on the etherscan side? Perhaps the api.etherscan side doesnt not have the most recent transaction information?
Any insights would be greatly appreciated!
Thanks!!
The txlist endpoint only returns transactions from and to to the specified address.
You're trying to view transactions from and to address 0x9bb1.... But this specific tx (on the screenshot) originated from 0x2204... and was sent to contract 0x30ad....
The 0x9bb1... only acts in the event logs produced by the transactions, and most likely the tx was executing a transfer() function with this address as a param.
TLDR: When you're transfering tokens, you're sending a transaction to the token contract - not to the token recepient.

ERC20 token , transferfrom crashes , what would be the consequences?

We have created an ERC20 token for TGE/ICO .
In our testing we have found that transferFrom function does not work and crashes
rest all the functions are working properly . the tokens are already deployed on mainnet
what impact will this have apart from user not able to transfer on someone's behalf ?
Also will this impact later when the token comes on exchange in anyway ? or user is only going to use transfer function?
What do you mean by "crashes"? Are transactions rolled back and the resulting state correct or are tokens lost/irretrievable as a result of using the function?
Either way, as a user I would not want to purchase your token. If one of the ERC20 functions doesn't work properly, I certainly wouldn't have trust that the contract is secure. The impact will be that you will have irate customers who won't want your token. Users will expect to be able to use the transferFrom function since you're advertising your token as an ERC20 compliant token. I'd also think that no exchange will accept your token.