-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice.js
More file actions
65 lines (57 loc) · 1.6 KB
/
practice.js
File metadata and controls
65 lines (57 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const pinataSDK = require('@pinata/sdk');
const pinata = pinataSDK('71084a474f5f077b9699', '5d9f0655f5b4194f2e0bfac0eff6fe0005a242c8af72bed24cf78cb61619d7da');
/* test Authentication
pinata.testAuthentication().then((result) => {
//handle successful authentication here
console.log(result);
}).catch((err) => {
//handle error here
console.log(err);
});
*/
var i = 2; //gimme_duck index
var result_ = '';
const fs = require('fs');
const readableStreamForFile = fs.createReadStream('./second_duck.png');
const options = {
pinataMetadata: {
name: "GIMMEDUCK_TEST"+i,
keyvalues: {
customKey: 'gimmeduck_test'+i,
}
},
pinataOptions: {
cidVersion: 0
}
};
pinata.pinFileToIPFS(readableStreamForFile, options).then((result) => {
console.log("File Uploaded!");
console.log(result);
result_ = result.IpfsHash;
/*pin JSON to IPFS*/
const body = {
"name":"Gimme_duck"+i,
"description":"Gimme_duck upload practice!",
"image":"ipfs://"+result_,
"attributes":[{"trait_type": "Unknown","value": "Unknown"}]
};
const options2 = {
pinataMetadata: {
name: "GIMMEDUCK_TEST_JSON"+i,
keyvalues: {
customKey: 'gimmeduck_test_json',
}
},
pinataOptions: {
cidVersion: 0
}
};
pinata.pinJSONToIPFS(body, options2).then((result2) => {
console.log("JSON Uploaded!");
console.log(result2);
}).catch((err2) => {
console.log(err2);
});
}).catch((err) => {
console.log(err);
});