@alexkeating/common-utilities
Version:
Our **Common Utilities** package is a set of helper tools and utilities that are used throughout our libraries and apps. This includes things like our constants, types that are commonly shared across packages, and various utilities and helper functions.
32 lines • 1.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.pinataPostJSON = exports.PINATA_PIN_JSON = void 0;
const tslib_1 = require("tslib");
exports.PINATA_PIN_JSON = 'https://api.pinata.cloud/pinning/pinJSONToIPFS';
const pinataPostJSON = ({ creds, jsonString, }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
try {
const response = yield fetch(exports.PINATA_PIN_JSON, {
method: 'POST',
headers: {
pinata_api_key: creds.pinata_api_key,
pinata_secret_api_key: creds.pinata_api_secret,
'Content-Type': 'application/json',
},
body: jsonString,
});
const data = yield response.json();
if (typeof (data === null || data === void 0 ? void 0 : data.IpfsHash) === 'string') {
return data;
}
else {
console.log('response', response);
throw new Error(`IPFS Pin failed.`);
}
}
catch (err) {
console.error(err);
throw new Error(`IPFS Pin failed.`);
}
});
exports.pinataPostJSON = pinataPostJSON;
//# sourceMappingURL=ipfs.js.map