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 an Amazon Managed Blockchain (AMB) Access endpoint for Polygon Proof of Stake (PoS) Mainnet using Accessor tokens. It also includes sample code to obtain the current block height.

Note

In line with Polygon's deprecation of Mumbai announced on March 27 2024, we will cease support of AMB Access Mumbai on April 15 2024. AMB Access Polygon Mainnet will continue to be available as Public Preview. We will continue evaluating support for Amoy Testnet in AMB Access. Please contact us if you would like to learn more.

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

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 the Polygon Mainnet network.
  4. Select your created Accessor and copy the Token parameter. AWS Console: Token Based Access

Replace <TOKEN> in the following endpoint with your copied Token for Polygon Mainnet:

Polygon Mainnet

https://mainnet.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 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 Polygon PoS Mainnet. Now that you are familiar with AMB Access Polygon, explore how to Deploy a Smart Contract on Polygon Mainnet 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.