@samudai_xyz/web3-sdk
Version:
## All in one web3 integrations for Samudai
90 lines (89 loc) • 4.41 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.NFTClaim = void 0;
const ethers_1 = require("ethers");
const abi_json_1 = __importDefault(require("../contracts/abi.json"));
const constants_1 = require("../utils/constants");
// import { initFunction } from '../../biconomy'
class NFTClaim {
constructor(env) {
var _a;
this.chainId = null;
this.contractAddress = '';
this.gatewayURL = '';
this.claimNFT = async (provider, phase
// jwt: string
) => {
try {
if (provider && this.contractAddress) {
// const smartAccount = await initFunction(provider)
const signer = provider.getSigner();
const address = await signer.getAddress();
const contract = new ethers_1.ethers.Contract(this.contractAddress, abi_json_1.default, signer);
// /**
// * @param {uint256} phase - phase number(0,1,2,3 ...)
// * @param {uint64} 1 - quantity of NFTs to mint
// */
// const erc20Interface = new ethers.utils.Interface([
// 'function mintPhase(uint256 phaseIndex, uint64 quantity)',
// ])
// // Encode an ERC-20 token transfer to recipientAddress of the specified amount
// const encodedData = erc20Interface.encodeFunctionData('mintPhase', [
// phase,
// 1,
// ])
// const tx = {
// to: this.contractAddress, // destination smart contract address
// data: encodedData,
// }
const tx = await contract.mintPhase(phase, 1);
// // Optional: Transaction subscription. One can subscribe to various transaction states
// // Event listener that gets triggered once a hash is generetaed
// smartAccount.on('txHashGenerated', (response: any) => {
// console.log('txHashGenerated event received via emitter', response)
// })
// smartAccount.on('onHashChanged', (response: any) => {
// console.log('onHashChanged event received via emitter', response)
// })
// // Event listener that gets triggered once a transaction is mined
// smartAccount.on('txMined', (response: any) => {
// console.log('txMined event received via emitter', response)
// })
// // Event listener that gets triggered on any error
// smartAccount.on('error', (response: any) => {
// console.log('error event received via emitter', response)
// })
// Sending gasless transaction
// const txResponse = await smartAccount.sendTransaction({
// transaction: tx,
// })
// console.log('userOp hash', txResponse.hash)
// If you do not subscribe to listener, one can also get the receipt like shown below
// const txReciept = await txResponse.wait()
// console.log('Tx hash', txReciept.transactionHash)
// DONE! You just sent a gasless transaction
await tx.wait();
if (tx) {
return true;
}
else {
return false;
}
}
else {
throw new Error('Invalid provider or contract address');
}
}
catch (err) {
throw err;
}
};
//this.chainId = chainId
this.gatewayURL = ((_a = constants_1.GatewayURL.find((item) => item.env === env)) === null || _a === void 0 ? void 0 : _a.url) || '';
this.contractAddress = '0x1376BEC5669cC194255231A27a333396bBC93368';
}
}
exports.NFTClaim = NFTClaim;