This Script will be getting a Solana owned account/ list of Solana owned accounts as input and then it will be doing the following work:
- Fetching the list of historical transaction signatures for each account
- Fetching the detail of each transaction signature, representing the details of every historical transaction that involved a Solana owned account
- Load it into BigQuery
Basically, this script loads historical data related to solana owned accounts into the BigQuery table
Prerequisites:
- A
Schema Filenamed asbq_loadin.jsonformat to be passed it to the BigQuery Table - A
Source Filenamed asAcc_to_checkto read Accounts to be checked, in the.txtformat - A
Service Accountwith Required Permissions (i.e., BigTable Read, BigQuery Write) and itsCredentialskey file - The
Script Filenamed asMain_Script.py,Setup_Credential.py,Helper_Script.pyat one place
$ solana-ledger-tool bigtable transaction-history -l . [SOLANA_OWNED_ACCOUNT]Output: List of transaction signatures
xxxxxuQfUxaxx2xLx9xxxmxxxxxRxQxxxpx3xSxxxHxxx3x4x3xUxxxxexcxTxyxMxExxxzx
xyxxxPxtx6xexRxwxWxxxZxgxxxfx8xZxXxkxSxxxYxxxLxxxBxmxQ7xxx3VyFxrxXxkxxxx
xxxxxxxhxxxxhxxxx32xxxxxxxixmxxxxx3xxxx2xnxxmxxxx1xxyx8xxxrxex8xxxxx-xxx$ curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":xxxxxx, "id":xxxxx, "method":"getConfirmedTransaction", "params":["[TRANSACTION_SIGNATURE]","json"]}' https://api.mainnet-beta.solana.comOutput: Detail of each transaction signature
{"jsonrpc":"xxxx.xxxx","result":{"blockTime":xxxxxxxxxxx,"meta":{"err":xxxxxxx,"fee":xxxxxx,"innerInstructions":[],"logMessages":["Program xxxxxxxxxxxxxxxx invoke [x]","Program xxxxxxxxxxxx success"],"postBalances":[xxxx,xxxxx,xxxx],"postTokenBalances":[],"preBalances":[xxxx,xxxx,xxxx],"preTokenBalances":[],"rewards":[],"status":{xxx:xxx}},"slot":xxxx,"transaction":{"message":{"accountKeys":[xxx,xxxx,xxxx],"header":{"numReadonlySignedAccounts":xxx,"numReadonlyUnsignedAccounts":xxxx,"numRequiredSignatures":xxxx},"instructions":[{"accounts":[xxxxx,xxxxx],"data":xxxxxxxx,"programIdIndex":xxxxxxx}],"recentBlockhash":xxxxxxxxxxxxxxxxxxxxxx},"signatures":[xxxxxxxxxxxxxxxxxxxxxxxxxxxxx]}},"id":xxxx}$ bq load --autodetect --source_format=NEWLINE_DELIMITED_JSON [DATASET_NAME].[BIG_QUERY_TABLE_NAME] [SOURCE_FILE_LOCATION.json] .[SCHEMA_FILE_LOCATION.json]Steps:
- Install the
gcloudexecutable and set it inPATH - Install the
python 3.xand set it inPATH - Install the
solana-ledger-toolexecutable and set it inPATH
Then Run the script using python3 [SCRIPT_FILENAME.PY]
- Setup the gcloud credentials:
(a). Need to create a service account with necessary permissions (i.e., BigTable Read, BigQuery Write) and then create and save a key file of it
gcloud iam service-accounts create SERVICE_ACCOUNT_ID \
--description="DESCRIPTION" \
--display-name="DISPLAY_NAME"(b). Optional: To grant your service account an IAM role on your project
gcloud projects add-iam-policy-binding PROJECT_ID \
--member="serviceAccount:SERVICE_ACCOUNT_ID@PROJECT_ID.iam.gserviceaccount.com" \
--role="ROLE_NAME"(c). Optional: To allow users to impersonate the service account,
gcloud iam service-accounts add-iam-policy-binding \
SERVICE_ACCOUNT_ID@PROJECT_ID.iam.gserviceaccount.com \
--member="user:USER_EMAIL" \
--role="roles/iam.serviceAccountUser"(d). To Create a new key file
gcloud iam service-accounts keys create KEY_FILE \
--iam-account=SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.comOutput: A Service account is created and its key file is now downloaded to your machine.
- To setup PATH for gcloud, solana-ledger-tool
export $PATH=PATH:/[LOCATION_OF_APPLICATIONS-EXE_FILE]Example:
If for solana-ledger-tool the location is /home/[USER]/.local/share/solana/install/release/xxx/xxlxxexx/solana-release/bin/solana-ledger-tool then the path will be
export $PATH=PATH:/home/[USER]/.local/share/solana/install/release/xxx/xxlxxexx/solana-release/binIf for solana-ledger-tool the location is /home/[USER]/.local/share/solana/install/releases/xxxxx/solana-release/bin/google-cloud-sdk/bin/gcloud
export $PATH=PATH:/home/[USER]/.local/share/solana/install/releases/xxxxx/solana-release/bin/google-cloud-sdk/binNote:
To find path for a .exe use find / -iname [NAME_OF_EXE]
Example:
find / -iname solana-ledger-tool
- Use the parameters like key's file-name and the service-account-emailid used to create that key, and replace the corresponding reference inside the file named as Setup_Credential.py.
Example:
cred = str(output11) + '/[KEY-FILE-NAME.json]'gcloud auth activate-service-account [EMAILID-OF-SERVICE-ACCOUNT]- Change the permissions of the file named as
write-all-stake-accounts.shby running the command
chmod +x write-all-stake-accounts.sh