UNPKG

@alexkeating/common-utilities

Version:

Our **Common Utilities** package is a set of helper tools and utilities that are used throughout our libraries and apps. This includes things like our constants, types that are commonly shared across packages, and various utilities and helper functions.

35 lines 1.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getNonce = exports.encodeFunction = exports.encodeValues = void 0; const ethers_1 = require("ethers"); const encodeValues = (typesArray, valueArray) => { return ethers_1.ethers.utils.defaultAbiCoder.encode(typesArray, valueArray); }; exports.encodeValues = encodeValues; const encodeFunction = (abi, fnName, functionArgs) => { try { if (!abi || !Array.isArray(functionArgs)) throw new Error('Incorrect params passed to safeEncodeHexFunction in abi.js'); const abiString = JSON.stringify(abi); const ethersInterface = new ethers_1.ethers.utils.Interface(abiString); return ethersInterface.encodeFunctionData(fnName, functionArgs); } catch (error) { console.error('error', error); return { error: true, message: 'Could not encode transaction data with the values entered into this form', }; } }; exports.encodeFunction = encodeFunction; const getNonce = (length = 24) => { let text = ''; const possible = '0123456789'; for (let i = 0; i < length; i++) { text += possible.charAt(Math.floor(Math.random() * possible.length)); } return text; }; exports.getNonce = getNonce; //# sourceMappingURL=encoding.js.map