opensea-js
Version:
TypeScript SDK for the OpenSea marketplace helps developers build new experiences using NFTs and our marketplace data
37 lines (32 loc) • 895 B
text/typescript
import { ethers } from "ethers";
// Re-export all utilities from specialized modules
export * from "./converters";
export * from "./chain";
export * from "./fees";
export * from "./protocol";
/**
* Estimate gas usage for a transaction.
* @param provider The Provider
* @param from Address sending transaction
* @param to Destination contract address
* @param data Data to send to contract
* @param value Value in ETH to send with data
*/
export async function estimateGas(
provider: ethers.Provider,
{ from, to, data, value = 0n }: ethers.Transaction,
) {
return await provider.estimateGas({
from,
to,
value: value.toString(),
data,
});
}
interface ErrorWithCode extends Error {
code: string;
}
export const hasErrorCode = (error: unknown): error is ErrorWithCode => {
const untypedError = error as Partial<ErrorWithCode>;
return !!untypedError.code;
};