import Web3 from 'web3'; import { Web3Service } from '@app/_services/web3.service'; const abi: Array = require('@src/assets/js/block-sync/data/TokenUniqueSymbolIndex.json'); const web3: Web3 = Web3Service.getInstance(); export class TokenRegistry { contractAddress: string; signerAddress: string; contract: any; constructor(contractAddress: string, signerAddress?: string) { this.contractAddress = contractAddress; this.contract = new web3.eth.Contract(abi, this.contractAddress); if (signerAddress) { this.signerAddress = signerAddress; } else { this.signerAddress = web3.eth.accounts[0]; } } public async totalTokens(): Promise { return await this.contract.methods.entryCount().call(); } public async entry(serial: number): Promise { return await this.contract.methods.entry(serial).call(); } public async addressOf(identifier: string): Promise { const id: string = web3.eth.abi.encodeParameter('bytes32', web3.utils.toHex(identifier)); return await this.contract.methods.addressOf(id).call(); } }