dethcrypto/eth-sdk

eth-sdk assumes it's ran on the backend

hasparus opened this issue · 1 comments

Problem

The sdk reads JSON ABI from a relative filepath using fs and __dirname. It's not trivial to use it in a frontend project.

ESM support is also lacking.

Solution

We could inline the ABI or require it as a JavaScript module instead. (It's already inlined in factory generated by TypeChain generated.)

Attachments

current eth-sdk-client/index.js

function getContract(address, abiPath, defaultSigner) {
    const abi = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, '..\..\..\eth-sdk\abis', abiPath + '.json'), 'utf-8'));
    return new ethers_1.Contract(address, abi, defaultSigner);``
}
exports.getContract = getContract;
function getMainnetSdk(defaultSigner) {
    return {
        "dai": getContract('0x6B175474E89094C44Da98b954EedeAC495271d0F', 'mainnet/dai', defaultSigner),
    };
}