Ankr: Deploy a Smart Contract on Polygon using Ankr that is backed up to Filebase
Learn how to deploy an app on Polygon using Ankr that is backed up to Filebase.
Last updated
Was this helpful?
Learn how to deploy an app on Polygon using Ankr that is backed up to Filebase.
Last updated
Was this helpful?
Ankr is an API and blockchain node utility that can be used to create API projects and deploy your own blockchain nodes.
The Ankr API can be used in a variety of different applications, making it useful for project development and application creation. Ankr offers a selection of public API endpoints, so there is no need for an account to get started. To create custom, private apps, check out their guide on creating your own Polygon API endpoint .
In this guide, we’ll use HardHat and Ankr to create a an example app deployed on the using the Polygon Mumbai blockchain network that is backed up to an IPFS bucket on Filebase.
This guide was written and tested using Ubuntu 20.04. Commands and workflow may vary depending on your operating system.
To do this, navigate to . If you don’t have an account already, , then log in.
Select ‘Create Bucket’ in the top right corner to create a new bucket.
Bucket names must be unique across all Filebase users, be between 3 and 63 characters long, and can contain only lowercase characters, numbers, and dashes.
Set up a credentials file for S3FS at ${HOME}/.passwd-s3fs.
You will need to save your Filebase Access and Secret keys to this file and give it owner permissions. You can do so with the following commands:
echo ACCESS_KEY_ID:SECRET_ACCESS_KEY > ${HOME}/.passwd-s3fs
chmod 600 ${HOME}/.passwd-s3fs
You can mount a Filebase IPFS bucket with the command:
s3fs mybucket /path/to/mountpoint -o passwd_file=${HOME}/.passwd-s3fs -o url=https://s3.filebase.com
mybucket: name of your Filebase bucket
/path/to/mountpoint
cd /path/to/mounted/bucket
mkdir polygon-project
cd polygon-project
npm init
Provide any necessary configuration options for your workspace, or accept the default configuration settings for your npm workspace.
npm install --save-dev hardhat
npx hardhat
Select the ‘Create an empty hardhat.config.js’ option.
mkdir contracts
mkdir scripts
Contracts will be used for storing our smart contract code files.
Scripts will be used for storing script files used to deploy and interact with our contract.
HelloWorld.sol
. Open this file in your IDE of choice, and enter the following content:
This is a sample Hello World smart contract that creates a sample application using a Hello World function.
dotenv
package into your project directory:npm install dotenv --save
.env
file.Note: This .env file will hold your Ankr API URL and your Metamask Private Key. Do not use this method if you are utilizing a public Filebase bucket. This method is only recommended for use with a private Filebase bucket so that your information is secure.
Enter the following content in your .env file:
npm install --save-dev @nomiclabs/hardhat-ethers "ethers@^5.0.0”
hardhat.config.js
file. Replace the contents with the following:npx hardhat compile
Navigate into the scripts directory and create a new file called deploy.js
with the following content:
npx hardhat run scripts/deploy.js --network polygon_mumbai
Congrats! You’ve deployed a simple smart contract onto the Polygon Mumbai network! To get a more detailed idea of what happened behind the scenes, take a look at the Ankr API dashboard for your project. From there, you can see all of the requests made with your API URL, and the associated JSON RPC for each request.
ACCESS_KEY_ID is your Filebase Access key, and SECRET_ACCESS_KEY is your Filebase Secret key. For more information on Filebase access keys, see .
This contract uses the Ankr public Polygon endpoint. Learn more about Ankr by checking out their website