Bitcoin Forum
April 25, 2024, 10:06:19 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Retrieve my bitcoin data on blockchain.info using Excel VBA  (Read 1200 times)
Latinoz71 (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 0


View Profile
May 08, 2015, 10:37:00 PM
 #1

I got a web wallet on blockchain.info. It has several addres.
How can i retrieve my transactions (sent and received), and for every movement some data (date and time, amount, hash, MY NOTE, address RECEIVED...) using their api and my excel VBA sheet?
I imagine reading on internet that i must use some JSON request and read the site's answer, but i don't know how to start. The API for all are described here: https://blockchain.info/it/api/blockchain_api
Can anyone here help me please?
After 2day i'm able to put json string in a Excel-VBA variable. Here's the code:
Code:
Option Explicit

Sub ReadJsonAndParse()
    Dim strURL As String
    Dim xmlHttp As Object
    Dim strReturn As String

    strURL = "https://blockchain.info/it/address/15YMyRVQ1wyLsfwGP9Le97D3BRVG3nMjVW?format=json"

    'Open URL and get JSON data
     Set xmlHttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")
     xmlHttp.Open "GET", strURL
     xmlHttp.setRequestHeader "Content-Type", "text/xml"
     xmlHttp.send

     'Save the response to a string
     strReturn = xmlHttp.responseText
End Sub
In the "strReturn" there is the whole retrieved string; i noticed i got in the part called ROOT some data i need: (address, total_received, total_sent and final_balance) and the number of transaction for the address, 3 transaction in total for this address ("n_tx": 3,) numbered 0,1 and 2. Each of this got a "hash" that i want retrieve, but it seems very hard to do. The amount of each transaction is in the array but i don't know how extract.
In the retrieved string i can't find my "NOTE" as i wrote in the page "My Wallet --> Transactions (recent)" near the yellow icon with a green plus (+) into. Where are them?
Tnx in advance at all.
1714039579
Hero Member
*
Offline Offline

Posts: 1714039579

View Profile Personal Message (Offline)

Ignore
1714039579
Reply with quote  #2

1714039579
Report to moderator
1714039579
Hero Member
*
Offline Offline

Posts: 1714039579

View Profile Personal Message (Offline)

Ignore
1714039579
Reply with quote  #2

1714039579
Report to moderator
"I'm sure that in 20 years there will either be very large transaction volume or no volume." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714039579
Hero Member
*
Offline Offline

Posts: 1714039579

View Profile Personal Message (Offline)

Ignore
1714039579
Reply with quote  #2

1714039579
Report to moderator
1714039579
Hero Member
*
Offline Offline

Posts: 1714039579

View Profile Personal Message (Offline)

Ignore
1714039579
Reply with quote  #2

1714039579
Report to moderator
someguy123
Sr. Member
****
Offline Offline

Activity: 336
Merit: 254


CEO of Privex Inc. (www.privex.io)


View Profile WWW
May 08, 2015, 11:06:01 PM
 #2

In the retrieved string i can't find my "NOTE" as i wrote in the page "My Wallet --> Transactions (recent)" near the yellow icon with a green plus (+) into. Where are them?
I don't think they have an API which includes the "notes". They aren't put into the actual blockchain, they're on BC.INFO's database instead.


Each transaction has inputs and outputs:
If a transaction has an input with your address on it, that means you are SENDING coins
If a transaction has an output with your address on it, that means you are RECEIVING coins

To get total amount:
for amounts sent in a transaction, look for inputs with your address on, total the values of those
for amounts received in a transaction, look for outputs with your address on, total the values of these

Latinoz71 (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 0


View Profile
May 08, 2015, 11:15:42 PM
 #3

Many thanks for the rapid answer. The problem is i don't know how navigate into a json response string using VBA and Excel.
hexafraction
Sr. Member
****
Offline Offline

Activity: 392
Merit: 259

Tips welcomed: 1CF4GhXX1RhCaGzWztgE1YZZUcSpoqTbsJ


View Profile
May 08, 2015, 11:18:59 PM
 #4

You could work with ScriptControl and/or JScriptTypeInfo (as JSON is just JavaScript that describes an object):

Code:
Option Explicit

Private ScriptEngine As ScriptControl

Public Sub InitScriptEngine()
    Set ScriptEngine = New ScriptControl
    ScriptEngine.Language = "JScript"
    ScriptEngine.AddCode "function getProperty(jsonObj, propertyName) { return jsonObj[propertyName]; } "
    ScriptEngine.AddCode "function getKeys(jsonObj) { var keys = new Array(); for (var i in jsonObj) { keys.push(i); } return keys; } "
End Sub

Public Function DecodeJsonString(ByVal JsonString As String)
    Set DecodeJsonString = ScriptEngine.Eval("(" + JsonString + ")")
End Function

Public Function GetProperty(ByVal JsonObject As Object, ByVal propertyName As String) As Variant
    GetProperty = ScriptEngine.Run("getProperty", JsonObject, propertyName)
End Function

Public Function GetObjectProperty(ByVal JsonObject As Object, ByVal propertyName As String) As Object
    Set GetObjectProperty = ScriptEngine.Run("getProperty", JsonObject, propertyName)
End Function

Public Function GetKeys(ByVal JsonObject As Object) As String()
    Dim Length As Integer
    Dim KeysArray() As String
    Dim KeysObject As Object
    Dim Index As Integer
    Dim Key As Variant

    Set KeysObject = ScriptEngine.Run("getKeys", JsonObject)
    Length = GetProperty(KeysObject, "length")
    ReDim KeysArray(Length - 1)
    Index = 0
    For Each Key In KeysObject
        KeysArray(Index) = Key
        Index = Index + 1
    Next
    GetKeys = KeysArray
End Function

Example usage:

Code:
    JsonString = "{""key1"": ""val1"", ""key2"": { ""key3"": ""val3"" } }"
    Set JsonObject = DecodeJsonString(CStr(JsonString))
    Keys = GetKeys(JsonObject)

source

I have recently become active again after a long period of inactivity. Cryptographic proof that my account has not been compromised is available.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!