UNPKG

@samudai_xyz/web3-sdk

Version:

## All in one web3 integrations for Samudai

57 lines (56 loc) 2.31 kB
import { ethers } from 'ethers'; import ContractABI from '../contracts/abi.json'; import { GatewayURL } from '../utils/constants'; export 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.Contract(this.contractAddress, ContractABI, signer); const message = JSON.stringify({ address: address, timestamp: Date.now(), message: 'I am claiming this subdomain', }); const encoded = ethers.utils.solidityKeccak256(['string'], [message]); const signature = await signer.signMessage(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 = GatewayURL.find((item) => item.env === env)) === null || _a === void 0 ? void 0 : _a.url) || ''; this.contractAddress = '0xfFAeF3F8A37014B932334D283f90a2408Eba0328'; } }