1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 10:30:04 +01:00
metamask-extension/shared/modules/contract-utils.ts

24 lines
517 B
TypeScript
Raw Normal View History

type contract = {
contractCode: string | null;
isContractAddress: boolean;
};
export const readAddressAsContract = async (
ethQuery: {
getCode: (address: string) => string;
},
address: string,
): Promise<contract> => {
let contractCode;
try {
contractCode = await ethQuery.getCode(address);
} catch (e) {
contractCode = null;
}
const isContractAddress = contractCode
? contractCode !== '0x' && contractCode !== '0x0'
: false;
return { contractCode, isContractAddress };
};