Getting Started with AMB Access Polygon

3 minute read
Content level: Foundational
1

Learn how to get started with Amazon Managed Blockchain (AMB) Access Polygon

Introduction

This guide shows you how to configure Amazon Managed Blockchain (AMB) Access endpoints for both Polygon Proof of Stake (PoS) and the Mumbai Testnet using Accessor tokens. It also includes sample code to obtain the current block height.

Prerequisites

An AWS Account that has the appropriate IAM permissions for AMB Access Polygon. For this tutorial, you can use the AmazonManagedBlockchainFullAccess managed policy.

Automated endpoint configuration

If you prefer to use the AWS Console, you can skip to the next section.

If you’ve installed and configured the AWS Command Line Interface (CLI) with the proper permissions, you can run the following commands to generate an Accessor token. These commands use the AWS CLI to call the create-accessor method and extract the BillingToken parameter. This value is then stored in an environment variable, appended to the service endpoint, and displayed in the terminal.

Polygon Mainnet

billing_token_mainnet=$(aws managedblockchain create-accessor --accessor-type=BILLING_TOKEN --network-type=POLYGON_MAINNET --query 'BillingToken' --output text);  mainnet_endpoint="https://mainnet.polygon.managedblockchain.us-east-1.amazonaws.com/?billingtoken=${billing_token_mainnet}"; echo "Polygon Mainnet Endpoint:"; echo $mainnet_endpoint

Mumbai Testnet

billing_token_testnet=$(aws managedblockchain create-accessor --accessor-type=BILLING_TOKEN --network-type=POLYGON_MUMBAI --query 'BillingToken' --output text); testnet_endpoint="https://mumbai-testnet.polygon.managedblockchain.us-east-1.amazonaws.com/?billingtoken=${billing_token_testnet}"; echo "Polygon Mumbai Testnet Endpoint:"; echo $testnet_endpoint

Now that your service endpoint is set up, you can proceed to the Test your AMB Access Polygon endpoint section.

Creating an Accessor Token in the AWS Console

  1. Navigate to the Amazon Managed Blockchain service page in the AWS Console.
  2. Select Token Accessors from the side bar under Access.
  3. Click Create Accessor and choose either the Polygon Mainnet or Mumbai network.
  4. Select your created Accessor and copy the Token parameter. AWS Console: Token Based Access

Replace <TOKEN> in the following endpoints with your copied Token for either Mainnet or Mumbai Testnet:

Polygon Mainnet

https://mainnet.polygon.managedblockchain.us-east-1.amazonaws.com/?billingtoken=<TOKEN>

Mumbai Testnet

https://mumbai-testnet.polygon.managedblockchain.us-east-1.amazonaws.com/?billingtoken=<TOKEN>

Important: You must never embed Accessor tokens in user-facing applications. If you prioritize security and auditability over convenience, use the SigV4 signing process instead.

Test your AMB Access Polygon endpoint

Prerequisite: Node.js (version 18 or above)
  1. Create a project directory and install web3.js:
mkdir AMBPolygon && cd AMBPolygon && npm install web3
  1. Create a new file (e.g test.js) in your directory and copy the following code:
const { Web3 } = require('web3');

// Initialize with your AMB Access Polygon Mainnet or Mumbai Testnet endpoint:
const web3 = new Web3('YOUR_AMB_ACCESS_ENDPOINT');

web3.eth.getBlockNumber().then(console.log);
  1. Execute the script by running:
node test.js

Conclusion

You have configured your AMB Access Polygon endpoint with your Accessor token and received the current block height for either Polygon PoS Mainnet or Mumbai Testnet. Now that you are familiar with AMB Access Polygon, explore how to Deploy a Smart Contract on the Polygon Mumbai network with Hardhat Ignition.

Please leave a comment below if you have any questions. If you would like to learn more about AMB Access Polygon, you can refer to the documentation. Remember to prioritize security, especially with your Amazon Managed Blockchain Accessor token.