filswan / js-mcs-sdk Goto Github PK
View Code? Open in Web Editor NEWjs-sdk for multichain storage service
License: MIT License
js-sdk for multichain storage service
License: MIT License
require('dotenv').config('./.env')
const fs = require('fs').promises
const { mcsClient } = require('mcs-client')
const client = new mcsClient({
privateKey: process.env.PRIVATE_KEY,
rpcUrl: process.env.RPC_URL,
})
async function main() {
const fileArray = [
{ fileName: 'AAAA', file: await fs.readFile('./AAAA') },
{ fileName: 'BBBB', file: await fs.readFile('./BBBB') },
{ fileName: 'CCCC', file: await fs.readFile('./CCCC') },
]
const options = {
delay: 1,
duration: 525,
fileType: 0,
}
const uploadResponses = await client.upload(fileArray, options)
console.log(uploadResponses)
const payloadCid = uploadResponses[0].data.payload_cid
const tx = await client.makePayment(payloadCid, '0.002')
console.log(tx.transactionHash)
const nft = {
name: 'NFT',
description: 'NFT',
image: uploadResponses[0].data.ipfs_url,
tx_hash: '0x...',
}
const mintTx = await client.mintAsset(payloadCid, nft)
console.log(mintTx)
}
main()
这样写只能批量上传,但是只有第一个文件被支付和铸造。
应该怎么改? @rykci
When I run the js-mcs-sdk test.js:
PS C:\Users\12109\Desktop\mcs-client> node .\test.js
TypeError: Cannot read properties of undefined (reading 'name')
at FormData._getContentDisposition (C:\Users\12109\node_modules\form-data\lib\form_data.js:227:40)
at FormData._multiPartHeader (C:\Users\12109\node_modules\form-data\lib\form_data.js:178:33)
at FormData.append (C:\Users\12109\node_modules\form-data\lib\form_data.js:71:21)
at uploadPromise (C:\Users\12109\node_modules\mcs-client\helper\upload.js:16:8)
at C:\Users\12109\node_modules\mcs-client\helper\upload.js:39:7
at async Promise.all (index 0)
at async mcsUpload (C:\Users\12109\node_modules\mcs-client\helper\upload.js:52:20)
at async mcsClient.upload (C:\Users\12109\node_modules\mcs-client\index.js:54:5)
at async test (C:\Users\12109\Desktop\mcs-client\test.js:21:26)
C:\Users\12109\Desktop\mcs-client\test.js:22
console.log(uploadResponse[0].data.payload_cid)
^
TypeError: Cannot read properties of undefined (reading '0')
at test (C:\Users\12109\Desktop\mcs-client\test.js:22:29)
Here is the test.js code :
require('dotenv').config('C:\\Users\\12109\\.env')
const fs = require('fs')
const { mcsClient } = require('mcs-client')
const client = new mcsClient({
privateKey: process.env.PRIVATE_KEY,
})
const test = async () => {
const fileArray = [
{ fileName: 'jstest', file: fs.createReadStream('./jstest.txt') },
]
const options = {
delay: 1000,
duration: 180,
fileType: 0,
}
const uploadResponse = await client.upload(fileArray, options)
console.log(uploadResponse[0].data.payload_cid)
console.log(uploadResponse[0].data.ipfs_url)
}
test()
node and npm version:
PS C:\Users\12109\Desktop\mcs-client> node -v
v16.13.1
PS C:\Users\12109\Desktop\mcs-client> npm -v
8.1.2
PS C:\Users\12109\Desktop\mcs-client>
What's wrong with me???
如果文件上传完毕后没有进行铸造, 那么以后铸造时该如何获取文件的ipfs_url?
require('dotenv').config('./.env')
const fs = require('fs').promises
const { mcsClient } = require('mcs-client')
const client = new mcsClient({
privateKey: process.env.PRIVATE_KEY,
rpcUrl: process.env.RPC_URL,
})
async function main() {
const payloadCid = 'bafykbzacXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
const tx = await client.makePayment(payloadCid, '0.001')
console.log(tx.transactionHash)
}
main()
运行后 支付成功并输出tx_hash ,可通过浏览器查到交易详情。
但网页依旧显示未支付,且无法手动支付。
Hi,
I have been having difficulties recently with paying for storage on the testnet even though I believe I have enough funds in wallet.
Below is the error and file details (uploaded to IPFS already). Status appears to be always "pending". Please advise. Thanks.
I have the following fund in test wallet:
0.0968
MATIC
197
USDC
/node_modules/web3-core-helpers/lib/errors.js:28
var err = new Error('Returned error: ' + message);
^
Error: Returned error: insufficient funds for gas * price + value
at Object.ErrorResponse (../node_modules/web3-core-helpers/lib/errors.js:28:19)
at ../node_modules/web3-core-requestmanager/lib/index.js:300:36
at ../node_modules/web3-providers-http/lib/index.js:124:13
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
data: null
}
// [
// {
// status: 'success',
// data: {
// source_file_upload_id: 476742,
// payload_cid: 'Qmerw1LjXrcm52y6RoTSmFiZHuHqWKzJ5b8dzpkoofuELf',
// ipfs_url: 'https://calibration-ipfs.filswan.com/ipfs/Qmerw1LjXrcm52y6RoTSmFiZHuHqWKzJ5b8dzpkoofuELf',
// file_size: 19,
// w_cid: '8a1c9f2d-853d-49b2-a87b-299fb21f5d92Qmerw1LjXrcm52y6RoTSmFiZHuHqWKzJ5b8dzpkoofuELf'
// }
// }
// ]
/ [
// {
// source_file_upload_id: 476742,
// car_file_id: 0,
// file_name: 'JnK0N.txt',
// file_size: 19,
// upload_at: 1659664087,
// duration: 525,
// ipfs_url: 'https://calibration-ipfs.filswan.com/ipfs/Qmerw1LjXrcm52y6RoTSmFiZHuHqWKzJ5b8dzpkoofuELf',
// pin_status: 'Pinned',
// payload_cid: '',
// w_cid: '8a1c9f2d-853d-49b2-a87b-299fb21f5d92Qmerw1LjXrcm52y6RoTSmFiZHuHqWKzJ5b8dzpkoofuELf',
// status: 'Pending',
// deal_success: false,
// is_minted: false,
// token_id: null,
// mint_address: null,
// nft_tx_hash: null,
// offline_deal: []
// },
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.