diff --git a/packages/codegen/src/templates/indexer-template.handlebars b/packages/codegen/src/templates/indexer-template.handlebars index 70607b0c..4abd9e0d 100644 --- a/packages/codegen/src/templates/indexer-template.handlebars +++ b/packages/codegen/src/templates/indexer-template.handlebars @@ -134,17 +134,14 @@ export class Indexer { {{#if (compare query.mode @root.constants.MODE_ETH_CALL)}} const contract = new ethers.Contract(contractAddress, this._abi, this._ethProvider); - const { block: { number } } = await this._ethClient.getBlockByHash(blockHash); - const blockNumber = ethers.BigNumber.from(number).toNumber(); - {{#if (compare query.returnType 'bigint')}} let value = await contract.{{query.name}}( - {{~#each query.params}}{{this.name}}, {{/each}}{ blockTag: blockNumber }); + {{~#each query.params}}{{this.name}}, {{/each}}{ blockTag: blockHash }); value = value.toString(); value = BigInt(value); {{else}} const value = await contract.{{query.name}}( - {{~#each query.params}}{{this.name}}, {{/each}}{ blockTag: blockNumber }); + {{~#each query.params}}{{this.name}}, {{/each}}{ blockTag: blockHash }); {{/if}} const result: ValueResult = { value }; diff --git a/packages/erc20-watcher/src/indexer.ts b/packages/erc20-watcher/src/indexer.ts index 95c974b5..f44c7304 100644 --- a/packages/erc20-watcher/src/indexer.ts +++ b/packages/erc20-watcher/src/indexer.ts @@ -124,7 +124,7 @@ export class Indexer { const contract = new ethers.Contract(token, this._abi, this._ethProvider); // eth_call doesnt support calling method by blockHash https://eth.wiki/json-rpc/API#the-default-block-parameter - const value = await contract.balanceOf(owner, { blockTag: blockNumber }); + const value = await contract.balanceOf(owner, { blockTag: blockHash }); result = { value: BigInt(value.toString()) @@ -160,7 +160,7 @@ export class Indexer { if (this._serverMode === ETH_CALL_MODE) { const contract = new ethers.Contract(token, this._abi, this._ethProvider); - const value = await contract.allowance(owner, spender, { blockTag: blockNumber }); + const value = await contract.allowance(owner, spender, { blockTag: blockHash }); result = { value: BigInt(value.toString()) diff --git a/packages/uni-watcher/src/indexer.ts b/packages/uni-watcher/src/indexer.ts index 791f66c4..68f88284 100644 --- a/packages/uni-watcher/src/indexer.ts +++ b/packages/uni-watcher/src/indexer.ts @@ -295,11 +295,8 @@ export class Indexer implements IndexerInterface { async callGetPool (blockHash: string, contractAddress: string, key0: string, key1: string, key2: number): Promise { const contract = new ethers.Contract(contractAddress, factoryABI, this._ethProvider); - const { block: { number } } = await this._ethClient.getBlockByHash(blockHash); - const blockNumber = ethers.BigNumber.from(number).toNumber(); - try { - const value = await contract.getPool(key0, key1, key2, { blockTag: blockNumber }); + const value = await contract.getPool(key0, key1, key2, { blockTag: blockHash }); return { value }; } catch (error: any) { @@ -317,11 +314,8 @@ export class Indexer implements IndexerInterface { async positions (blockHash: string, contractAddress: string, tokenId: string): Promise { const contract = new ethers.Contract(contractAddress, nfpmABI, this._ethProvider); - const { block: { number } } = await this._ethClient.getBlockByHash(blockHash); - const blockNumber = ethers.BigNumber.from(number).toNumber(); - try { - const value = await contract.positions(tokenId, { blockTag: blockNumber }); + const value = await contract.positions(tokenId, { blockTag: blockHash }); return { value }; } catch (error: any) {