require('dotenv').config()
const { mcsSDK } = require('js-mcs-sdk')
const fs = require('fs') // used to read files
// set up js-mcs-sdk
const mcs = new mcsSDK({
privateKey: process.env.PRIVATE_KEY,
rpcUrl: process.env.RPC_URL,
})
async function main() {
// ENTER PARAMETERS
const PATH_1 = ''
const PATH_2 = ''
const fileArray = [
{ fileName: 'file1', file: fs.createReadStream(PATH_1) },
{ fileName: 'file2', file: fs.createReadStream(PATH_2) },
]
//optional, showing default options
const options = {
delay: 1000, // delay between upload API calls for each file. May need to be raised for larger files
duration: 525, // the number of days to store the file on the Filecoin network.
fileType: 0, // set to 1 for nft metadata files. type 1 files will not show on the UI.
}
const uploadResponses = await mcs.upload(fileArray, options)
console.log(uploadResponses)
}
main()
参数
fileArray: 对象数组
fileName:文件名
file:文件内容(使用fs是获取文件内容的简单方法)
options:还可以传递可选对象以指定某些参数:
delay:上传 API 调用之间的延迟(以毫秒为单位)。默认值为 1000,但对于许多较大的文件,可能需要增加