Skip to content

Commit

Permalink
extract _call method
Browse files Browse the repository at this point in the history
  • Loading branch information
vanruch committed Apr 8, 2024
1 parent 7b15836 commit 2daf290
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions evm/evm-codec/src/contract-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,23 @@ export class ContractBase {
}
}

/**
* Call a contract function using eth_call with the given calldata.
* Might be necessary to override for some chains.
*/
private async rpc_call(calldata: string) {
return this._chain.client.call("eth_call", [
{ to: this.address, data: calldata },
"0x" + this.blockHeight.toString(16),
]);
}

async eth_call<
const T extends Struct,
const R extends Codec<any> | Struct | undefined
>(func: AbiFunction<T, R>, args: StructTypes<T>): Promise<R> {
let data = func.encode(args);
let result = await this._chain.client.call("eth_call", [
{ to: this.address, data },
"0x" + this.blockHeight.toString(16),
]);
const data = func.encode(args);
const result = await this.rpc_call(data);
return func.decodeResult(result);
}
}

0 comments on commit 2daf290

Please sign in to comment.