0.1.2 β€’ Published 12 months ago

abitty v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

Abitty πŸ‘Œ

Abitty cherry-picks specific functions from your Solidity ABIs and saves them for individual importing. Stop using thicc JSON files, start shaking that tree.

Configuration

Create abitty.config.json in your project directory.

{
    "outputDir": "./src/types",
    "organize": true,
    "contracts": [
        {
            "name": "foo",
            "abiPath": "../out/Foo.sol/Foo.json",
            "pick": ["someFunction", "someOtherFunction", "amazingFunction"]
        },
        {
            "name": "bar",
            "abiPath": "../out/Bar.sol/Bar.json",
            "pick": ["excellentFunction"]
        }
    ]
}

Config spec

keyrequired
outputDirRelative path where the generated files will goYes
organizeIf true, organizes contract files in folders and creates a single entrypointNo
contractsAn array of Contracts πŸ‘‡Yes
Contract.nameUsed for generating folder names, required if organize is set to trueSometimes
Contract.abiPathPath to your Solidity build artifact's JSON fileYes
Contract.pickFunctions you want to useYes

Generating your files

Install as a dev dependency and add to your package scripts

npm install abitty --save-dev
"scripts": {
    "gimme-them-abis": "abitty"
},

or skip this above and run with npx

npx abitty

The script will output an individual .ts file for each function, plus a helper type you can use to ensure arguments passed to that function satisfy the ABI.

If you are using a different configuration file, pass it to Abitty with the --config-file flag.

Using your exports

They work great with Viem / Wagmi which you should definitely be using.

import { doTheFooAbi, DoTheFooArgs } from 'yourOutputDir/foo/doTheFoo';

await publicClient.simulateContract({
    abi: [doTheFooAbi],
    address: fooAddress,
    functionName: 'doTheFoo',
    args: [myArg1, myArg2, myArg3],
    account: userAccount,
});

// You can use the generated argument typings like so:
const myArgs = [myArg1, myArg2, myArg3] satisfies DoTheFooArgs;

MIT license, do whatever you want with it. Contributions welcome.

Like it? Love it? Donate a few dollars to your local humane society for the fluffies 🐢🐱

0.1.2

12 months ago

0.1.1

12 months ago

0.1.0

12 months ago