ERC20 Tokens Transferred Information from Transaction Hash - php

EtherScan provides a API for transaction details It's part of Geth/Parity Proxy APIs by name eth_getTransactionByHash, But I am unable to get information what ERC20 token was transferred and how many.
I need Token Details and Number of token transferred with the help of Transaction Hash.

You are using the wrong API.
To get an ERC20 transfer's information, you need the transaction receipt, since transfer information is recorded in a transfer event log. You should be using eth_getTransactionReceipt.
This will give you a response such as this, for this tx:
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"blockHash": "0xc5e5a515898983d1370d40b03fc05ae08be861af746a1577796153a149a1bb20",
"blockNumber": "0x5ff5dd",
"contractAddress": null,
"cumulativeGasUsed": "0xe85fb",
"from": "0xd7afd4441fccc118b9207b0e136f4ef9319b3c79",
"gasUsed": "0x9034",
"logs": [
{
"address": "0x0d8775f648430679a709e98d2b0cb6250d2887ef",
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
"0x000000000000000000000000d7afd4441fccc118b9207b0e136f4ef9319b3c79",
"0x00000000000000000000000069d9e9aff57ec73582ad1ce441726dba7ea78fe0"
],
"data": "0x0000000000000000000000000000000000000000000001054aefee8ba6d00000",
"blockNumber": "0x5ff5dd",
"transactionHash": "0x3265c1461d3f167c756fbc062ae3a2dc279b44a9c3ca2194271d4251cd0c1655",
"transactionIndex": "0x1b",
"blockHash": "0xc5e5a515898983d1370d40b03fc05ae08be861af746a1577796153a149a1bb20",
"logIndex": "0xa",
"removed": false
}
],
"logsBloom": "0x04000000002000000200000000000000002000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000008000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000200010000000000000000000000000000000000000000000000100000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"status": "0x1",
"to": "0x0d8775f648430679a709e98d2b0cb6250d2887ef",
"transactionHash": "0x3265c1461d3f167c756fbc062ae3a2dc279b44a9c3ca2194271d4251cd0c1655",
"transactionIndex": "0x1b"
}
}
Of this, this logs section is important.
The format of an ERC20 transfer log is Transfer(address from, address to, uint256 value). When you take the keccak hash for Transfer(address,address,uint256), you get 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef for the topic, as shown in the response above.
The next two value in that log are the from and to addresses respectively, packed as normal for ETH (zero padded until 32 bytes). Lastly, the data within the log is the value of the ERC20 token that was transferred (BAT in this example).
The address that emits the log, 0x0d8775f648430679a709e98d2b0cb6250d2887ef in this case, is the token contract. You can then read the token symbol, name, and decimals from this contract using eth_call API to read the token information.

Related

Watson Assistant CURL API: How to send follow up message?

I'm trying out IBM Watson Assistant. Ultimate goal is to integrate it with my custom PHP backend, via it's Watson Assistant's cURL API Endpoints (because there's no complete PHP SDK yet).
Let me tell what I did so far:
Imported a sample Workspace from a Training Data Set.
Then I tried this, and it works fine.
Then I tried that exact same thing via cURL API, I got a response like this: (The json output format beautified)
.
{
"intents": [
{
"intent": "locate_amenity",
"confidence": 0.999901008605957
}
],
"entities": [
{
"entity": "amenity",
"location": [
7,
10
],
"value": "gas",
"confidence": 1
}
],
"input": {
"text": "i need some gas"
},
"output": {
"text": [
"Hi. It looks like a nice drive today. What would you like me to do? "
],
"nodes_visited": [
"Start And Initialize Context"
],
"log_messages": []
},
"context": {
"conversation_id": "153c18ee-1015-4b6a-ae04-789e29bf4a05",
"system": {
"dialog_stack": [
{
"dialog_node": "root"
}
],
"dialog_turn_counter": 1,
"dialog_request_counter": 1,
"_node_output_map": {
"Start And Initialize Context": [
0,
0
]
},
"branch_exited": true,
"branch_exited_reason": "completed"
},
"AConoff": "off",
"lightonoff": "off",
"musiconoff": "off",
"appl_action": "",
"heateronoff": "off",
"volumeonoff": "off",
"wipersonoff": "off",
"default_counter": 0,
"previous_cuisine": "",
"previous_restaurant_date": "",
"previous_restaurant_time": ""
}
}
Now please let me understand 2 things here.
Question (1)
At this point, I was expecting the API to return with a message:
"There are gas stations nearby. Which one would you like to drive to?"
But why it doesn't. If then, how do I achieve it?
Question (2)
How do I properly reply back with "Go to number 5." so that the API understands I'm referring to the previous Call? (aka) How to I continue the dialog flow? (Note: I tried sending back with the previous "contexts", "entities", "intents", but it is somehow still recognised as a new message.)
Please share me an example of cURL call to follow up the previous message.
Since there's no complete PHP SDK yet, it is very hard for me to understand just by the cURL API calls. API Documentation does not explain to that details too. Please help.
Thank you all.
The message API for Watson Assistant is stateless. Everything that is needed to process a request is submitted as parameters. This includes the message itself, but also the context. The context holds the state about where in the dialog tree the conversation is. It could also hold information that is transferred from WA to the app, e.g., to process a client-side action. Or from the app to WA, e.g., with a record from a database.
Coming to your request:
Your dialog probably sends out that reponse when a new conversation is started. I see it is the same as in the "Try it out".
You would need to send a "Hi" or empty message first, wait for the reponse from WA, then send your "I need gas" together with the context data you received from WA. WHen you look into the details, you see the dialog stack, turn counter and more. The conversation ID is the identifier for that current chat.
With the above, WA's next response should be exactly like in the "Try it out" because you went down in the dialog tree.

Which parameters are needed to use GET verify_credentials Twitter API method?

i just need some help with Twitters' API
I used the sign in with twitter flow to get the tokens needed to make calls to the API, there weren't any problems with the implementation, and so far I have got both oauth_token and oauth_token_secret so I think I have what I need to use the API.
The problem is about the last method which the documentation said about verif credentials, I am supposed to use that GET method to get a json with information about the user which has just logged into twitter by my app, however, Twitter docu doesn't mention anything about what parameters I need to pass or what headers, just the url.
I used php curl to make the calls to the API, do you know what parameters I need to pass to the API to finally get the json?
Here you have the link to the API docu:
https://dev.twitter.com/rest/reference/get/account/verify_credentials
Thanks in advance.
No params, just the 'Authorization' header.
Use the "OAuth Signature Generator" on the link you included to generate a test request and confirm yourself.
You just need to properly sign the request. This provides the context including the user, since it implicitly includes details about your request, the client secret, the user token etc.
$ oksocial https://api.twitter.com/1.1/account/verify_credentials.json
{
"id": 999999,
"id_str": "999999",
"name": "Bobby Bonson",
"screen_name": "xxxx",
"location": "CA",
"description": "...",
"url": null,
"entities": {
"description": {
"urls": []
}
},
"protected": false,
"followers_count": 699,
"friends_count": 631,
"listed_count": 34,

GA not tracking certain actions

Our site is tracking CC and other transaction just fine, but has a problem with EFT transactions.
I have established that we are writing to the socket that is listening for GA calls with the correct information (compared it to another action that is being tracked correctly).
I need some help debugging the issue and was wondering if there was anywhere on the GA interface that I could see attempted and failed calls?
The moment you see it in the interface it's by definition not a failed call so, no, but there is a debugger extension that writes errors (if any) to the browser console.
If you do your tracking serverside (as you are talking about sockets) you could log the outgoing tracking calls to a file and send them to the debug endpoint by inserting the word "debug" after the hostname (so this would look something like google-analytics.com/debug/collect?v=1&tid=.....).
The debug endpoint will return a json response that points out missing or invalid fields. Example response below:
{
"hitParsingResult": [ {
"valid": false,
"parserMessage": [ {
"messageType": "ERROR",
"description": "The value provided for parameter 'tid' is invalid. Please see http://..... for details.",
"messageCode": "VALUE_INVALID",
"parameter": "tid"
} ],
"hit": "/debug/collect?v=1\u0026_v=j41d\u0026a=335525335\u0026t=pageview\u0026_s=1\u0026dl=file%3A%2F%2F%2FUsers%2Fepierstorff%2FDesktop%2Ftest.html\u0026dp=http%3A%2F%2F%2FUsers%2Fepierstorff%2FDesktop%2Ftest.html\u0026ul=de\u0026de=windows-1252\u0026dt=OFfline\u0026sd=24-bit\u0026sr=2560x1440\u0026vp=2385x678\u0026je=0\u0026fl=21.0%20r0\u0026_u=QEAAAIABI~\u0026jid=2113413999\u0026cid=761062822.1461745183\u0026tid=UA-XXXXXX-X\u0026_r=1\u0026z=140208380"
} ],
"parserMessage": [ {
"messageType": "INFO",
"description": "Found 1 hit in the request."
} ]
}

How to look up user information from Google GAIA ID?

I've been working on a Hangouts.json parser for Google's Takeout service that takes all of the conversations, attachments, and miscellaneous information from the json file and populates a database with everything. I've finished everything but the only information the json file provides for who sent what is a GAIA ID that I've been able to figure out is the unique ID Google uses between their services. The problem is I don't know how to look up any other information about the user such as the name they identify with or their email.
I know most of the information is publicly available as you can take the GAIA ID and put it into a URL like: https://plus.google.com/u/0/#####################/about where the #'s are the GAIA ID. This page will reveal their screen name publicly. When a email address is unknown the same thing can be inferred by using: reply-######################profiles.google.com where this will also be able to be used to contact them.
Ideally I'd like to be able to look up a user's screen name without having to parse that public Google+ page at least but a true email would be great as well. So ideally I'd like an API or other resource to look up screen names and / or email info from a GAIA ID.
IMPORTANT UPDATE
March 2019: This answer is still getting up votes, however Google are withdrawing / have withdrawn the Google Plus API.
You will need an alternative solution as this will no longer apply.
Original Reply
Use the Google Plus API: https://developers.google.com/+/api/
I've not tested specifically with Hangouts (I never knew there was a Hongouts API!) but it returns details given IDs from other APIs.
You can test it out here: https://developers.google.com/apis-explorer/#p/plus/v1/plus.people.get to see what you'll get.
The Gaia ID may be obtained with the People API, by requesting the metadata in the personFields.
You may try it with the Google APIs Explorer (sample links are provided below).
For any of your contacts (provided he/she is a google user), using the people.connections/list resource :
People API - people.connections/list - personFields=names,metadata
(I have included the names value in the personFields for better illustration, though it is not required to retrieve the Gaia Id)
Sample output (1XXXXXXXXXXXXXXXXXXXX is the Gaia Id):
{
"connections": [
{
"resourceName": "people/c42",
"etag": "...",
"metadata": {
"sources": [
{
"type": "CONTACT",
...
},
{
"type": "PROFILE",
"id": "1XXXXXXXXXXXXXXXXXXXX",
...
"profileMetadata": {
"objectType": "PERSON",
"userTypes": [
"GOOGLE_USER"
]
}
}
....
],
"objectType": "PERSON"
}
"names": [
{
...
"displayName": "John Doe",
...
}
]
},
...
}
For yourself or any user using the people/get resource
People API - people/get - personFields=metadata
In the resourceName field :
use people/me to obtain your informations.
use the resourceName value previously retrieved in a people.connections.list request to retrieve another user informations
Sample output (1XXXXXXXXXXXXXXXXXXXX is the Gaia Id):
{
"resourceName": "people/...",
"etag": "....",
"metadata": {
"sources": [
{
"type": "PROFILE",
"id": "1XXXXXXXXXXXXXXXXXXXX",
"etag": "...",
"profileMetadata": {
"objectType": "PERSON",
"userTypes": [
"GOOGLE_USER"
]
}
...
},
...
],
"objectType": "PERSON"
}
}
Go to google chat.
create a chat with the person you want to find gaia id.
tag the person in the chat window
(#name of person)
right click the name, click "Inspect"
There you will find the ID
data-user-id="10xxxxxxxxxxxxxxxxxxx
#Name of person

How to remove duplicate Facebook Access Tokens?

I have 100 Active Facebook access tokens.
For each account I have more than one access token.
I want to keep only one token for each account and want to delete the others.
And i don't want to do this manually so please post a PHP script which check all the tokens and keep only one active token for each account.
In such a case the simplest way to validate an access token is to issue the following request
https://graph.facebook.com/me?fields=id&access_token=#accesstoken
If the provided access token is not valid or expired Facebook will just return an error message of some sort. Such as :
{
"error": {
"message": "Error validating access token: This may be because the user logged out or may be due to a system error.",
"type": "OAuthException",
"code": 190,
"error_subcode": 467
}
}
For a valid access token the result will somehow look like this
{
"id": "ID_VALUE"
}

Categories