@hyperlane-xyz/sdk
Version:
The official SDK for the Hyperlane Network
34 lines • 1.08 kB
JavaScript
import { BigNumber } from 'ethers';
export const DEFAULT_CALL_GAS_FALLBACK = BigNumber.from(50_000);
/**
* Estimates gas for calling handle() on a recipient contract.
* Returns null if estimation fails (e.g., call would revert).
*/
export async function estimateHandleGasForRecipient(params) {
try {
// await required for catch to handle promise rejection
return await params.recipient.estimateGas.handle(params.origin, params.sender, params.body, { from: params.mailbox });
}
catch {
return null;
}
}
/**
* Estimates gas for a single contract call.
* Returns fallback value (default 50k) if estimation fails.
*/
export async function estimateCallGas(params) {
const fallback = params.fallback ?? DEFAULT_CALL_GAS_FALLBACK;
try {
// await required for catch to handle promise rejection
return await params.provider.estimateGas({
to: params.to,
data: params.data,
value: params.value,
});
}
catch {
return fallback;
}
}
//# sourceMappingURL=gas.js.map