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 to process.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.
require('dotenv').config()
const { mcsSDK } = require('js-mcs-sdk')
// set up js-mcs-sdk
const mcs = new mcsSDK({
privateKey: process.env.PRIVATE_KEY,
rpcUrl: process.env.RPC_URL,
})
require('dotenv').config()
const { mcsSDK } = require('js-mcs-sdk')
// set up js-mcs-sdk
const mcs = new mcsSDK({
privateKey: process.env.PRIVATE_KEY,
rpcUrl: process.env.RPC_URL,
})
async function main() {
// code snippets found in the documentation go here
}
main()