UNPKG

@kanalabs/mirai

Version:

Mirai - Account Abstraction SDK (EVM + non-EVM)

90 lines (89 loc) 4.07 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ERC721Helper = void 0; const ethers_1 = require("ethers"); const erc721_ABI_1 = require("./erc721-ABI"); class ERC721Helper { constructor(sdk, collectionAddress, walletProvider) { this.sdk = sdk; this.collectionAddress = collectionAddress; this.walletProvider = walletProvider; this.collection = new ethers_1.Contract(this.collectionAddress, erc721_ABI_1.ERC721_ABI, this.walletProvider); } name() { return __awaiter(this, void 0, void 0, function* () { const name = yield this.collection.functions.name(); return name[0]; }); } symbol() { return __awaiter(this, void 0, void 0, function* () { const symbol = yield this.collection.functions.symbol(); return symbol[0]; }); } balanceOf(address) { return __awaiter(this, void 0, void 0, function* () { const bal = yield this.collection.functions.balanceOf(address); return bal[0]; }); } ownerOf(tokenId) { return __awaiter(this, void 0, void 0, function* () { const owner = yield this.collection.functions.ownerOf(tokenId); return owner[0]; }); } getApproved(tokenId) { return __awaiter(this, void 0, void 0, function* () { const operator = yield this.collection.functions.getApproved(tokenId); return operator[0]; }); } isApprovedForAll(owner, operator) { return __awaiter(this, void 0, void 0, function* () { const isApproved = yield this.collection.functions.isApprovedForAll(owner, operator); return isApproved[0]; }); } tokenURI(tokenId) { return __awaiter(this, void 0, void 0, function* () { const uri = yield this.collection.functions.tokenURI(tokenId); return uri[0]; }); } approve(operator, tokenId) { return __awaiter(this, void 0, void 0, function* () { const transactionData = this.collection.interface.encodeFunctionData('approve', [operator, tokenId]); yield this.sdk.addUserOpsToBatch({ to: this.collectionAddress, data: transactionData }); }); } safeTransferFrom(from, to, tokenId) { return __awaiter(this, void 0, void 0, function* () { const transactionData = this.collection.interface.encodeFunctionData('safeTransferFrom', [from, to, tokenId]); yield this.sdk.addUserOpsToBatch({ to: this.collectionAddress, data: transactionData }); }); } transferFrom(from, to, tokenId) { return __awaiter(this, void 0, void 0, function* () { const transactionData = this.collection.interface.encodeFunctionData('transferFrom', [from, to, tokenId]); yield this.sdk.addUserOpsToBatch({ to: this.collectionAddress, data: transactionData }); }); } setApprovalForAll(operator, approved) { return __awaiter(this, void 0, void 0, function* () { const transactionData = this.collection.interface.encodeFunctionData('setApprovalForAll', [operator, approved]); yield this.sdk.addUserOpsToBatch({ to: this.collectionAddress, data: transactionData }); }); } } exports.ERC721Helper = ERC721Helper;