UNPKG

@samudai_xyz/web3-sdk

Version:

## All in one web3 integrations for Samudai

64 lines (63 loc) 2.65 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Subdomain = void 0; const ethers_1 = require("ethers"); const abi_json_1 = __importDefault(require("../contracts/abi.json")); const constants_1 = require("../utils/constants"); class Subdomain { constructor(env) { var _a; this.chainId = null; this.contractAddress = ''; this.gatewayURL = ''; this.claimSubdomain = async (username, provider // member_id: string, // jwt: string ) => { try { // const memberCountResult = await axios.get( // `${this.gatewayURL}/api/member/get/invitecount/${member_id}`, // { // headers: { // Authorization: `Bearer ${jwt}`, // }, // } // ) // const memberCount = memberCountResult.data.data.count if (provider && this.contractAddress) { const signer = provider.getSigner(); const address = await signer.getAddress(); const contract = new ethers_1.ethers.Contract(this.contractAddress, abi_json_1.default, signer); const message = JSON.stringify({ address: address, timestamp: Date.now(), message: 'I am claiming this subdomain', }); const encoded = ethers_1.ethers.utils.solidityKeccak256(['string'], [message]); const signature = await signer.signMessage(ethers_1.ethers.utils.arrayify(encoded)); const tx = await contract.claimSubdomain(username, message, signature); 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 = '0xfFAeF3F8A37014B932334D283f90a2408Eba0328'; } } exports.Subdomain = Subdomain;