How to analyze blockchain data with natural language queries using Amazon Bedrock

4 minute read
Content level: Foundational
0

Learn how to chat with blockchain data and gain insights

Introduction

Blockchain networks like Bitcoin and Ethereum store vast amounts of data that can drive business decisions, inform investment strategies, and uncover emerging trends. However, accessing and interpreting this data has traditionally been complex due to its raw, byte-encoded format. This tutorial guides you through setting up a solution using Amazon Bedrock and the AWS Public Blockchain Datasets, enabling you to query blockchain data using natural language. This makes the process of gaining insights from Web3 data more intuitive and accessible.

For a deeper dive into the solution and its architecture, you can refer to this blog post.

Prerequisites
  1. Install the latest version of the AWS CDK with the following command:
npm install -g aws-cdk
  1. Ensure Docker is installed and running.
  2. Clone the GitHub repository:
git clone https://github.com/aws-samples/chat-with-blockchain-data-with-amazon-bedrock.git
cd chat-with-blockchain-data-with-amazon-bedrock
  1. Install dependencies:
npm install
  1. Configure your AWS profile:
aws configure
  1. Bootstrap your AWS environment:
cdk bootstrap aws://<ACCOUNT_NUMBER>/<REGION>

Deployment

  1. Deploy the AWS CDK stack with the following command:
cdk deploy BedrockBlockchainDataAgentStack

This command will deploy all necessary resources for the solution.

Configuration

Enable Model Access (if not already enabled):

  • Go to the Amazon Bedrock Console and navigate to “Model access”.
  • Enable access for the Anthropic Claude 3 Haiku model.

Testing the Solution

  1. Navigate to the Amazon Bedrock console and choose "Agents" under Builder Tools.
  2. Select the agent named bedrock-agent-*.
  3. Enter a natural language query and run it (e.g., “What was the largest Bitcoin transaction yesterday?”).

Example Queries

Bitcoin:

  • Find the total number of Bitcoin transactions that occurred in the last 24 hours.

  • Identify the largest BTC transaction in the last hour.

  • Calculate the average block size over the last day.

  • What is Satoshi’s message that he stored in the genesis block?

Ethereum:

  • Get the number of new Ethereum contracts created in the last week.
  • Find the most active Ethereum address in the last 7 days.
  • Calculate the total value of all token transfers in the Ethereum network in the last 30 days.
  • Identify the largest Ethereum transaction in the last month.

Clean Up

Destroy the deployed resources with the following command:

cdk destroy

Extending the Solution

  • Integrate with Amazon Managed Blockchain (AMB) Query:
    • AMB Query offers faster and more cost-effective data retrieval compared to querying raw datasets with Athena. For example, retrieving a Bitcoin address balance using AMB Query is significantly faster and cheaper.
  • Use The Graph:
    • The Graph is a decentralized protocol for querying blockchain data. Integrating The Graph allows users to ask natural language questions about specific smart contracts and associated data.
  • Implement Guardrails for Amazon Bedrock:
    • Guardrails for Amazon Bedrock help ensure security by detecting and blocking potentially malicious user inputs, maintaining the integrity and reliability of the solution.

Conclusion

This tutorial has demonstrated how to leverage Amazon Bedrock and the AWS Public Blockchain datasets to enable natural language querying of blockchain data. By simplifying the process, it lowers the barrier to entry and makes valuable insights accessible to a broader range of users. The solution can be extended further by integrating additional data sources and implementing security measures, ensuring a robust and versatile tool for blockchain data analysis.

Deploy this solution in your AWS account to explore its capabilities and tailor it to your specific needs. For a deeper dive into the details of the solution, you can refer to this article’s complementary blog post and its corresponding GitHub repository.

profile pictureAWS
EXPERT
published 3 months ago754 views