@volare.finance/utils.js
Version:
The Blockchain Utils
54 lines • 2.02 kB
JavaScript
;
/**
* @file creature.ts
* @author astra <astra@volare.finance>
* @date 2022
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Creature = void 0;
const tslib_1 = require("tslib");
const ethers_1 = require("ethers");
const Creature_json_1 = require("../artifacts/opensea/Creature.json");
const token_1 = require("../token");
class Creature extends token_1.ERC721 {
constructor(contract, endpoint) {
super(contract, endpoint);
this.contract = new ethers_1.Contract(contract, Creature.ABI(), this.provider);
}
static ABI() {
return Creature_json_1.abi;
}
contractURI() {
var _a;
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return (_a = this.contract) === null || _a === void 0 ? void 0 : _a.contractURI();
});
}
baseTokenURI() {
var _a;
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return (_a = this.contract) === null || _a === void 0 ? void 0 : _a.baseTokenURI();
});
}
redeem(signer, recipient, amount, nonce, signature) {
var _a;
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const tx = yield ((_a = this.contract) === null || _a === void 0 ? void 0 : _a.connect(signer).redeem(recipient, amount, nonce, signature));
const receipt = yield tx.wait();
const events = receipt.events;
const transfers = new Array();
for (let i = 0; i < events.length; i++) {
if (events[i].topics[0] !== Creature.Transfer_t0)
continue;
transfers.push({
from: '0x' + events[i].topics[1].substring(26),
to: '0x' + events[i].topics[2].substring(26),
tokenId: Number(events[i].topics[3]),
});
}
return transfers;
});
}
}
exports.Creature = Creature;
//# sourceMappingURL=creature.js.map