开始
This guide will explain how to install the js-mcs-sdk and its basic usage
Prerequisites
Node.js - This SDK was built using version v16.13.0 (npm v8.1.0)
Polygon Mumbai Testnet Wallet - Metamask Tutorial
Polygon Mumbai Testnet Alchemy RPC - Alchemy Tutorial
Mumbai Testnet USDC and MATIC funds are also necessary - Swan Faucet Tutorial
Installation
Install the package using npm. It is recommended to create a new directory for a new project. Run the init command to setup a package.json file
Environment Variables
Once you have your Mumbai wallet and RPC URL, create a file named .env
in your project directory and store your wallet's private key and the RPC URL.
Be careful not to expose this information! Revealing your private key to others will give them access to your wallet.
Writing SDK Scripts
To begin writing a script utilizing the SDK, create a new .js
file. Let's create a file named demo.js
At the top of this file, require the necessary packages for the script.
require('donenv').config()
will add the variables in your.env
file toprocess.env
const { mcsSDK } = require('js-mcs-sdk')
will require the SDK
Next, after requiring the SDK, we still need to initialize it
Now we can begin using the SDK methods. Since these functions are asynchronous, we will need to create an async
function to run the SDK methods.
This is the boilerplate code for all snippets found in the SDK documentation
Upload File Example
Here is a simple example to upload a single file to MCS. Made a new file named upload.js
Use the command node upload.js
to run the code. This snippet creates the MCS SDK instance, creates a JSON file with your wallet address, and uploads the file to MCS.
Last updated