Track smart contract transactions - ethereum

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!

Related

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).

airdrop and lock tokens for specific time

I want to airdrop and presale my won token
so in the next step I want to lock them until my IDO data come
and unlock in this time 30% of user wallet balances
and next month 50 %
what is the best way to do this
If you want your token to be sent to users when certain date comes automatically without backend or any users or you doing the transactions, it is not possible. Blockchain operations cannot be executed without calling a transaction using scripts by user or backend.
You can write the following airdrop contract to achieve desired result:
Users send stable coins to your airdrop contract. Addresses of these users should be stored in some place. You can store addresses and amounts of token buyers automatically (in arrays on the blockchain - address[] buyers, uint256[] amounts).
If you want users to click on button on website to receive available amount of tokens, your airdrop contract should have a method to send right amount of your token to caller if the caller sent stable coins before. This method should check, if msg.sender is in buyers (check in array can be expensive, you can create a buyers map only for this check) and if airdrop date has come (you can save timestamps in seconds in some array and check if any date has come via comparison with block.timestamp). If both requirements are met, contract sends tokens from your balance (transferFrom) or from its balance (transfer) following the exchange rate.
If you want send the transaction by yourself to give all tokens to buyers, you can make the method, which can be called only by you (Ownable will be very helpful). Inside this method, contract goes through buyers array and send amount[buyerIndex]*exchangeRate to each of them. This method doesn't require users to click on any buttons, but can be very expensive in gas and hence for you.

which is the best way to call send() for a smartcontract method?

I'm developing a new dapp and I'm wondering with current Ethereum state of network, which are correct parameters to send along with web3, i.e.
myconytact.methods.myfunction(<params>).send({from:address,?????})
my problem is gas, gas limit and so on. I should use estimateGas? and the put gas:gas in the object passed in send()?
Generally, you never need to put in gas or gas limit, as those are set by the user in his or her wallet when confirming the transaction.

Apple Wallet Event Pass - Device registration

We created a wallet pass and sent the wallet pass invitation email to end-users. However, there was an issue with the back-end APIs which prevented the Apple pass from automatically calling the device registration API.
The question I have is, do we need to re-inform all user to reinstall the Pass, or will the Pass automatically try re-registering by calling the device API.
Thank you.
The way you have worded your question possibly describes an impossible situation. A valid pass will always attempt to register. You state that your API was the issue, but an issue with a web service implementation would not prevent devices attempting to call it.
If the pass.json contains a valid https webServiceURL an authenticationToken, it will call the device registration endpoint after it has been added to the user's wallet. If the device does not get a 201 or 200 response, it will continue to retry, progressively backing off from every few seconds, to every few days for a period of around 2 weeks.
Therefore, if your pass.json contained the correct information; assuming that the issue was with your device registration endpoint and assuming that you picked up and addressed the issue quickly, then you should see device registrations coming in without having to do anything.
If it took longer than a couple of weeks or if you want to accelerate the process, you could ask your users to toggle the Automatic Notifications setting on the back of the pass. This will force the device to attempt a re-registration.
If however, the pass does not contain a webServiceURL, or if the webServiceURL was incorrect, then the device will not call back, or will call the incorrect endpoint. In this case, the only option is to have your users reinstall the pass. In this case, it is not your API that is causing the problem, but your passes.

Decoupled Message Queue Pattern for Login

Let's say a user accesses a resource and it maps to a handler foo().
In foo() I want to check if the user's session is valid.
For maximum decoupling (and for the sake of the example) I put the provided session ID into a message and push that into the queue VERIFY_SESSION where it is picked up by a subscribed worker.
The worker takes the session ID out of the message, checks the database, etc and then adds some data indicating the session is valid to the message before pushing it to VERIFIED_SESSIONS.
Question:
How do I get the information that the session is valid back into the worker that handles the user's connection?
If I subscribe all frontend workers to the queue VERIFIED_SESSIONS, there is no way of telling which worker will receive it.
All I can think of would be to basically implement RPC on top of the message queue, but that would defeat the purpose of having the queue to begin with.
What is the common pattern here?