Skip to content

Commit

Permalink
README.md: Update to use loader.getContract(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
shazow committed Jan 22, 2024
1 parent 019ae35 commit 1bed4d0
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,25 @@ What can WhatsABI do?

## Usage

Quick start:

```typescript
import { ethers } from "ethers";
import { whatsabi } from "@shazow/whatsabi";

const provider = ethers.getDefaultProvider(); // substitute with your fav provider
const address = "0x00000000006c3852cbEf3e08E8dF289169EdE581"; // Or your fav contract address

// Quick-start:

const result = await whatsabi.autoload(address, { provider });
console.log(result.abi);
// -> [ ... ]
```

Breaking it down:

```typescript
const code = await provider.getCode(address); // Load the bytecode

// Get just the callable selectors
Expand Down Expand Up @@ -62,16 +75,16 @@ console.log(await signatureLookup.loadEvents("0x721c20121297512b72821b97f5326877

// Here's a multiloader with an Etherscan API key, it can be used with autoload below.
// Each source will be attempted until a result is found.
const abiLoader = new whatsabi.loaders.MultiABILoader([
const loader = new whatsabi.loaders.MultiABILoader([
new whatsabi.loaders.SourcifyABILoader(),
new whatsabi.loaders.EtherscanABILoader({
apiKey: "...", // Replace the value with your Etherscan API key
}),
]);
console.log(await abiLoader.loadABI(address));
const { abi, name, /* ... other metadata */ } = await loader.getContract(address));
```

Bonus do-all-the-things helper:
All together with our do-all-the-things helper:

```typescript
...
Expand Down

0 comments on commit 1bed4d0

Please sign in to comment.