Rob or anyone who might help.
Ok so here goes what I am trying to achieve is a spreadsheet with a list of the optOut addresses and the Balance Amount of WFLR in each address and an aggregated total balance.
The BASIC script should first connect via http somehow to gather optOut addresses from 20.optOutAddresses in the original contract by running a loop starting at “0” and ending when an error message “(error) : (-32000) execution reverted “ is returned (approximately 220 addresses) instead of a valid address that starts with “0x”
and then next query the balance of WFLR for each opt-out address in the new contract at 2.balanceOf
Original contract DistributionToDelegators (0x9c7A4C83842B29bB4A082b0E689CB9474BD938d0) - Flare Explorer
New contract
The script so far as provided mostly by AI is as follows but it does not work and I am not clever enough to identify and rectify so I am appealing to this forum for help.
I have Libre Office Calc version Version: 7.6.4.1 (X86_64) / LibreOffice Community
Build ID: e19e193f88cd6c0525a17fb7a176ed8e6a3e2aa1
CPU threads: 8; OS: Windows 10.0 Build 19045; UI render: Skia/Raster; VCL: win
Locale: en-AU (en_AU); UI: en-GB
Calc: threaded
I have installed the getrest.oxt extension
' Function to parse JSON response and extract WFLR amounts
Function ParseResponse(jsonResponse As String) As Double
' Convert JSON response to a dictionary object
Dim json As Object
json = ParseJSON(jsonResponse)
' Initialize WFLR value
Dim wflrValue As Double
wflrValue = 0
' Assuming the JSON response is a dictionary with keys as addresses and values as WFLR amounts
Dim address As Variant
For Each address In json.Keys()
wflrValue = wflrValue + json(address)
Next address
' Return total WFLR value
ParseResponse = wflrValue
End Function
Sub QueryContracts()
Dim optOutAddresses() As String
Dim totalWFLR As Double
Dim index As Integer
' Initialize total WFLR and index
totalWFLR = 0
index = 0
' Loop to gather optOut addresses from the original contract
Do
' Construct URL for the original contract
Dim url As String
url = "https://flare-explorer.flare.network/address/0x9c7A4C83842B29bB4A082b0E689CB9474BD938d0/read-contract?20.optOutAddresses[" & index & "]"
' Make HTTP GET request using GetRest extension
Dim optOutJsonResponse As String
optOutJsonResponse = GetRest(url)
' Parse JSON response to get optOut address
Dim optOutAddress As String
optOutAddress = ParseResponse(optOutJsonResponse)
' Check if optOut address is valid
If optOutAddress <> "" Then
' Add optOut address to array
ReDim Preserve optOutAddresses(index)
optOutAddresses(index) = optOutAddress
' Increment index for next optOut address
index = index + 1
Else
' Exit loop if no more optOut addresses found
Exit Do
End If
Loop
' Query balance of WFLR for each optOut address in the new contract
For Each optOutAddress In optOutAddresses
' Construct URL for the new contract
Dim newContractUrl As String
newContractUrl = "https://flare-explorer.flare.network/token/0x1D80c49BbBCd1C0911346656B529DF9E5c2F783d/read-contract?2.balanceOf=" & optOutAddress
' Make HTTP GET request using GetRest extension
Dim balanceJsonResponse As String
balanceJsonResponse = GetRest(newContractUrl)
' Parse JSON response to get balance of WFLR
Dim balance As Double
balance = ParseResponse(balanceJsonResponse)
' Add balance to total WFLR
totalWFLR = totalWFLR + balance
Next optOutAddress
' Output total WFLR to cell A1 in the current sheet
ThisComponent.Sheets(0).getCellByPosition(0, 0).Value = "Total WFLR: " & Format(totalWFLR, "0.00")
End Sub