aws-samples
nft-deployment-amazon-managed-blockchain
JavaScript

Sample code and reference architecture to deploy an NFT on the Ethereum blockchain using Amazon Managed Blockchain

Last updated Dec 9, 2025
41
Stars
25
Forks
8
Issues
0
Stars/day
Attention Score
33
Language breakdown
JavaScript 81.1%
Solidity 18.4%
Dockerfile 0.5%
โ–ธ Files click to expand
README

Deploy NFT on Ethereum using Amazon Managed Blockchain

This repository contains sample code to deploy ERC-721 smart contracts on the Ethereum blockchain network using Amazon Managed Blockchain as a geth node. It provides a reference architecture for deploying a contract, minting NFT tokens and querying token owners using serverless components

The repo is structured as follows:

bash
.
โ”œโ”€โ”€ CODEOFCONDUCT.md
โ”œโ”€โ”€ CONTRIBUTING.md
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ images
โ””โ”€โ”€ serverless</code></pre>
   

Reference architecture

Architecture

Pre-requisites

1. An AWS account with a VPC and a public subnet. Ensure you have permissions to make objects in the S3 bucket public 2. AWS SAM CLI : Install the AWS SAM CLI. 3. Node.js: Install Node.js 14, including the npm package management tool. 4. Docker: Install Docker community edition.

Deploy Ethereum node and Serverless components

An AWS Serverless Application Model (SAM) template is used to deploy the stack

bash

cd serverless/

sam build

.... Building codeuri: /Users/pravincv/Nft-amb-repo/serverless/lambdas/nftmain runtime: nodejs14.x metadata: {} architecture: x86_64 functions: [&#39;nftmain&#39;] Running NodejsNpmBuilder:NpmPack Running NodejsNpmBuilder:CopyNpmrc Running NodejsNpmBuilder:CopySource Running NodejsNpmBuilder:NpmInstall Running NodejsNpmBuilder:CleanUpNpmrc

Build Succeeded</code></pre>

On success completion of the build, deploy the stack

bash

sam deploy --guided --capabilities CAPABILITYNAMEDIAM</code></pre>

Input the parameter values and confirm changes to deploy

Stack Name [nft-stack]: AWS Region [ap-southeast-1]: - region where Amazon Managed Blockchain is supported Parameter pEmail [name@example.com]: - email id that will receive Amazon SNS notifications Parameter pSubnetId [subnet-xxxxxxx]: - public subnet where the AWS Fargate task will run Parameter pNftBucketName [nftmetadata]: - bucket where NFT metadata will be stored Parameter pConfirmationBlocks [50]: - number of confirmations on the blockchain, to wait for Parameter pClusterName [nftcluster]: - AWS ECS cluster name Parameter pContainerName [rinkeby]: - name of container Parameter pRepositoryName [nftrepository]: - AWS ECR where the Docker images will be stored Parameter pIpRangeWhitelist [.../**]: - IP address CIDR that is allowed to invoke the API Parameter pNetworkId [n-ethereum-rinkeby]: - default network is rinkeby. Can choose ropsten if desired Parameter pInstanceType [bc.t3.large]: - choose desired instance size Parameter pAvailabilityZone [ap-southeast-1a]: - choose availability zone based on region Confirm changes before deploy [Y/n]: - confirm changes Y #SAM needs permission to be able to create roles to connect to the resources in your template Allow SAM CLI IAM role creation [Y/n]: - choose Y Save arguments to configuration file [Y/n]: -choose Y SAM configuration file [samconfig.toml]: - default file to save the samconfig SAM configuration environment [default]:

The following resources are created on deployment

SAM

This creates the following resources

  • nftmain - AWS Lambda function that provides APIs to deploy an ERC-721 contract to the Ethereum rinkeby test network, mint a new token as well get the owner of a specified token minted. The deploy API sends out an SNS message on successful deployment of a contract
* invokeFargateTask - This Lambda function is triggered by the AWS SNS message sent by the nftmain Lambda. On being triggered, it invokes a task that awaits until the rinkeby blockchain has confirmed the deployment confirmationBlocks (passed as an environment variable) number of times * ethTxnTopic - Amazon SNS topic to which nftmain Lambda published the transaction id on deployment of a contract * ethConfirmationTopic - Amazon SNS topic to which the task publishes a message on completing confirmationBlocks number of confirmations on the Rinkeby network * cluster and taskDefinition - cluster and task definition that provides the compute for the 'confirmation' logic * nftapi - api created and exposed via the api gateway for users to invoke HTTP POST * ecrRepository - repository where the docker image for the task is stored

To complete the serverless stack, create a Docker image and push to the ecrRepository by building, tagging and pushing the image as below.

bash
cd serverless/
  • aws ecr get-login-password --region &lt;region&gt; | docker login --username AWS --password-stdin &lt;account id&gt;.dkr.ecr.&lt;region&gt;.amazonaws.com
  • docker build -t nftrepository .
  • docker tag nftrepository:latest &lt;account&gt;.dkr.ecr.&lt;region&gt;&lt;.amazonaws.com/nftrepository:latest
  • docker push &lt;account&gt;.dkr.ecr.&lt;region&gt;.amazonaws.com/nftrepository:latest</code></pre>
To create a transaction on the Ethereum Rinkeby network, a private-public key pair is required. Generate the private key and upload to AWS SSM Parameter Store as an encrypted string as 'ethSystemKey'. - ensure the string excludes the first 2 characters, 0x of the privatekey . Add some ethereum test tokens for the rinkeby network by entering the public key https://faucets.chain.link/rinkeby and requesting ethereum test tokens. Please note that for AWS SSM Paramter Store might not be sufficient for some cases where wallets bear real funds.

EthereumKey

Deploying a test contract, minting an NFT and checking token ownership

Now we are ready to deploy an ERC-721 smart contract to the network.

 bash

โ”œโ”€โ”€ nftmain โ”‚ย ย  โ”œโ”€โ”€ NFTSamples โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ build โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ NFT_BaseURI.json โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ contracts โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ NFTSample.sol โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ NFT_BaseURI.sol โ”‚ย ย  โ”œโ”€โ”€ aws-web3-http-provider.js โ”‚ย ย  โ”œโ”€โ”€ deploy_contract.js โ”‚ย ย  โ”œโ”€โ”€ get_owner.js โ”‚ย ย  โ”œโ”€โ”€ index.js โ”‚ย ย  โ”œโ”€โ”€ mint_nft.js โ”‚ย ย  โ”œโ”€โ”€ package-lock.json โ”œโ”€โ”€ package.json โ””โ”€โ”€ utils.js โ””โ”€โ”€ txconfirmation โ””โ”€โ”€ index.js</code></pre> The contract to be deployed is stored in the nftmain directory under NFTSamples. We'll be using curl -X POST to deploy and mint the NFT. Obtain the API endpoint i.e InvokeURL from Amazon API Gateway ->APIs > Stages on the AWS Console.

bash   cd serverless/test-events

serverless/test-events โ”œโ”€โ”€ deploy.json โ”œโ”€โ”€ getowner.json โ””โ”€โ”€ mint.json</code></pre> Edit the deploy.json file to fill up the needed values.

 bash
&gt; cat deploy.json

{&quot;requestType&quot;: &quot;deploy&quot;, &quot;tokenName&quot;: &quot;coolnft&quot;, # name of nft &quot;tokenTicker&quot;: &quot;SYMB&quot;, # symbol &quot;metadataFilename&quot;: &quot;metadata.json&quot;, # name of metadata file &quot;metadata&quot;:{ #metadata associated with nft &quot;description&quot;: &quot;useful description&quot;, &quot;image&quot;: &quot;&lt;url of the image, preferably an IPFS hash&gt;&quot;, &quot;name&quot;: &quot; coolnft&quot; }} &gt; curl -X POST https://&lt;api&gt; .execute-api.&lt;region&gt;.amazonaws.com/nftapi -H &quot;Content-Type: application/json&quot; -d @deploy.json</code></pre>

The deploy command returns a transaction id hash and the contract address.

bash
{&quot;Transaction id&quot;:&quot;0x6b2af81c34055b678e5a8ae401f508fcbf950341df7e55e7372e80f75faf8afc&quot;,&quot;ContractAddress&quot;:&quot;0x8A3Ce65B266E8DE37Fe7d2e4911CA4578B5a7445&quot;

&gt; cat mint.json {&quot;requestType&quot;: &quot;mint&quot;, &quot;contractAddress&quot;: &quot;0x8A3Ce65B266E8DE37Fe7d2e4911CA4578B5a7445&quot;, -&gt; address of the contract address of the deployed contract &quot;mintAddress&quot;: &quot;0x905b8699E611a5F1f74BF5Cc3cCa2aCd175ec0c0&quot; -&gt; public key of any another wallet/address } &gt; curl -X POST https://&lt;api&gt;.execute-api.&lt;region&gt;.amazonaws.com/nftapi -H &quot;Content-Type: application/json&quot; -d @mint.json</code></pre> The response contains the transaction id ash

bash 
{&quot;Mint Tx Hash&quot;:&quot;0x960080892462ea76a90a5a00fe88ebc5d85d0b84d75e781ca5aa14e5829a0a14&quot;}
 &gt; cat getowner.json
 {&quot;requestType&quot;: &quot;mint&quot;,
&quot;contractAddress&quot;: &quot;0x8A3Ce65B266E8DE37Fe7d2e4911CA4578B5a7445&quot;,   -&gt; address of the contract address of the deployed contract
&quot;tokenID&quot;: &quot;0&quot;        -&gt; ID of the token that was minted previously
}

&gt; curl -X POST https://&lt;api&gt;.&lt;region&gt;.amazonaws.com/nftapi -H &quot;Content-Type: application/json&quot; -d @getowner.json</code></pre> The response provides the address of the owner for whom the token was minted.

bash {&quot;Owner address&quot;:&quot;0x905b8699E611a5F1f74BF5Cc3cCa2aCd175ec0c0&quot;}</code></pre>

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

๐Ÿ”— More in this category

ยฉ 2026 GitRepoTrend ยท aws-samples/nft-deployment-amazon-managed-blockchain ยท Updated daily from GitHub