SmartCheck Integration with Google Sheets
Certify your Google Sheets content directly from the server
SmartCheck is a Code Contract feature that allows you to generate unique, secure, and tamper-proof digital evidence in just seconds, at an affordable cost.
One of its most common use cases is the certification of content stored in Google Sheets. Below is a step-by-step guide on how to register and certify this information:
Step 1: Obtain the Authentication Token
To use the SmartCheck API, you must first authenticate via a POST request to obtain a JWT token.
Authentication Request (HTTP Request)
POST /login HTTP/1.1
Host: api.codecontract.io
Content-Type: application/json
{
"email": "[email protected]",
"password": "your_password"
}
Expected Response
HTTP/1.1 200 OK
Content-Type: application/json
{
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..."
}
Important:
✔️ The returned token must be stored and sent in every subsequent request as a Bearer Token in the Authorization header.
✔️ If Google Sheets uses OAuth for authentication, you must first obtain an OAuth token and send it to SmartCheck.
Step 2: Read Data from Google Sheets and Certify it with SmartCheck
You can use the Google Sheets API to extract data from a spreadsheet and send it to SmartCheck.
Example: Retrieve data from Google Sheets and certify it on the blockchain
1️⃣ Get Google Sheets data (Python example)
import gspread
from google.oauth2.service_account import Credentials
SCOPES = ["https://www.googleapis.com/auth/spreadsheets.readonly"]
SERVICE_ACCOUNT_FILE = "credentials.json"
def get_google_sheets_data(sheet_id, range_name):
""" Retrieve data from Google Sheets """
creds = Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES)
client = gspread.authorize(creds)
sheet = client.open_by_key(sheet_id).sheet1
data = sheet.get(range_name)
return data
# Replace with your Google Sheet ID and the range you want to read
SHEET_ID = "YOUR_SHEET_ID"
RANGE_NAME = "A1:D10"
spreadsheet_data = get_google_sheets_data(SHEET_ID, RANGE_NAME)
print("Data retrieved from Google Sheets:", spreadsheet_data)
2️⃣ Send the Google Sheets data to SmartCheck
import requests
def certify_google_sheets_data(data):
""" Send Google Sheets data to SmartCheck for certification """
url = "https://api.codecontract.io/smartcheck/createTreeAndRegisterMerkleRoot"
headers = {
"Authorization": "Bearer YOUR_TOKEN",
"Content-Type": "application/json"
}
payload = {
"data": data
}
response = requests.post(url, json=payload, headers=headers)
return response.json()
# Certify the retrieved Google Sheets data
certification_response = certify_google_sheets_data(spreadsheet_data)
print("Certification response:", certification_response)
Expected Response
{
"merkleRoot": "abc123...",
"transactionId": "tx123...",
"status": "success"
}
What does this mean?
✔️ merkleRoot: The Merkle root generated from the certified data.
✔️ transactionId: The ID of the blockchain transaction.
✔️ status: Indicates whether the certification was successful.
Step 3: Verify Certified Data in Google Sheets
If you need to verify that the data was certified, you can query the evidence in SmartCheck.
Request to get certification details
GET /smartcheck/reportsProofDetail?reportId=your_report_id HTTP/1.1
Host: api.codecontract.io
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...
Expected Response
{
"reportId": "your_report_id",
"merkleRoot": "abc123...",
"data": [
["ID", "Name", "Amount", "Date"],
["1", "Juan Pérez", "500", "2024-02-10"],
["2", "María López", "750", "2024-02-11"]
],
"status": "verified"
}
Summary
✔️ Step 1: Obtain the JWT token by authenticating with your Google Sheets account.
✔️ Step 2: Use the Google Sheets API to extract your data.
✔️ Step 3: Send the data to SmartCheck to certify it on the blockchain.
✔️ Step 4: Verify the certification whenever needed.
If you need more information or support, feel free to contact the Code Contract team. 🚀
