Commit 76ff5894 authored by Ori Pomerantz's avatar Ori Pomerantz Committed by GitHub

Update sdk.md

parent 7ceb3e10
...@@ -18,39 +18,34 @@ Install atst and it's peer dependencies. ...@@ -18,39 +18,34 @@ Install atst and it's peer dependencies.
npm npm
```bash ```bash
npm i @eth-optimism/atst wagmi @wagmi/core ethers@5.7.0 react react-dom npm i @eth-optimism/atst @wagmi/core ethers@5.7.0
``` ```
pnpm pnpm
```bash ```bash
pnpm i @eth-optimism/atst wagmi @wagmi/core ethers@5.7.0 react react-dom pnpm i @eth-optimism/atst @wagmi/core ethers@5.7.0
``` ```
yarn yarn
```bash ```bash
yarn add @eth-optimism/atst wagmi @wagmi/core ethers@5.7.0 react react-dom yarn add @eth-optimism/atst @wagmi/core ethers@5.7.0
``` ```
**Note:** As ethers v6 is not yet stable we only support ethers v5 at this time **Note:** As ethers v6 is not yet stable we only support ethers v5 at this time
<!--
## Basic usage ## Basic usage
All functions are fully tested. The tests (the files that end with `.spec.ts` under `.../src/lib`) are a great example to see usage examples.
### Setup ### Setup
atst uses `@wagmi/core` under the hood. atst uses `@wagmi/core` under the hood.
[See their documentation for more information](https://wagmi.sh/core/getting-started). [See their documentation for more information](https://wagmi.sh/core/getting-started).
```typescript ```javascript
import { connect, createClient } from '@wagmi/core' import { createClient } from '@wagmi/core'
import { providers, Wallet } from 'ethers' import { providers } from 'ethers'
const provider = new providers.JsonRpcProvider({ const provider = new providers.JsonRpcProvider({
url: "https://mainnet.optimism.io", url: "https://mainnet.optimism.io",
...@@ -68,8 +63,8 @@ createClient({ ...@@ -68,8 +63,8 @@ createClient({
Here is an example of reading an attestation used by the optimist nft Here is an example of reading an attestation used by the optimist nft
```typescript ```javascript
import { readAttestationString } from '@eth-optimism/atst' import { readAttestation } from '@eth-optimism/atst'
const creator = '0x60c5C9c98bcBd0b0F2fD89B24c16e533BaA8CdA3' const creator = '0x60c5C9c98bcBd0b0F2fD89B24c16e533BaA8CdA3'
const about = '0x2335022c740d17c2837f9C884Bfe4fFdbf0A95D5' const about = '0x2335022c740d17c2837f9C884Bfe4fFdbf0A95D5'
...@@ -98,13 +93,13 @@ await writeAttestation(preparedTx) ...@@ -98,13 +93,13 @@ await writeAttestation(preparedTx)
``` ```
## API ## API
-->
## High level API
### High level API
These functions are the easiest way to interact with the AttestationStation contract. These functions are the easiest way to interact with the AttestationStation contract.
### `prepareWriteAttestation` #### `prepareWriteAttestation`
[Prepares](https://wagmi.sh/core/actions/prepareWriteContract) an attestation to be written. [Prepares](https://wagmi.sh/core/actions/prepareWriteContract) an attestation to be written.
This function creates the transaction data, estimates the gas cost, etc. This function creates the transaction data, estimates the gas cost, etc.
...@@ -114,7 +109,7 @@ const preparedTx = await prepareWriteAttestation(about, key, 'hello world') ...@@ -114,7 +109,7 @@ const preparedTx = await prepareWriteAttestation(about, key, 'hello world')
console.log(preparedTx.gasFee) console.log(preparedTx.gasFee)
``` ```
### `readAttestation` #### `readAttestation`
[Reads](https://wagmi.sh/core/actions/readContract) and parses an attestation based on its data type. [Reads](https://wagmi.sh/core/actions/readContract) and parses an attestation based on its data type.
...@@ -131,7 +126,7 @@ const attestation = await readAttestation( ...@@ -131,7 +126,7 @@ const attestation = await readAttestation(
**Return Value:** The value attested by the `creator` on the `about` address concerning the `key`, when interpreted as the `dataType`. **Return Value:** The value attested by the `creator` on the `about` address concerning the `key`, when interpreted as the `dataType`.
If there is no such attestation the result is zero, `false`, or an empty string. If there is no such attestation the result is zero, `false`, or an empty string.
### `readAttestations` #### `readAttestations`
Similar to `readAttestation` but reads multiple attestations at once. Similar to `readAttestation` but reads multiple attestations at once.
Pass in a variadic amount of attestations to read. Pass in a variadic amount of attestations to read.
...@@ -151,7 +146,7 @@ const attestationList = await readAttestations({ ...@@ -151,7 +146,7 @@ const attestationList = await readAttestations({
### `writeAttestation` #### `writeAttestation`
[Writes the prepared tx](https://wagmi.sh/core/actions/writeContract). [Writes the prepared tx](https://wagmi.sh/core/actions/writeContract).
...@@ -160,11 +155,11 @@ const preparedTx = await prepareWriteAttestation(about, key, 'hello world') ...@@ -160,11 +155,11 @@ const preparedTx = await prepareWriteAttestation(about, key, 'hello world')
await writeAttestation(preparedTx) await writeAttestation(preparedTx)
``` ```
## Low level API ### Low level API
These definitions allow you to communicate with AttestationStation, but are not as easy to use as the high level API. These definitions allow you to communicate with AttestationStation, but are not as easy to use as the high level API.
### `ATTESTATION_STATION_ADDRESS` #### `ATTESTATION_STATION_ADDRESS`
The deployment address for the attestation station currently deployed with create2 on Optimism and Optimism Goerli `0xEE36eaaD94d1Cc1d0eccaDb55C38bFfB6Be06C77`. The deployment address for the attestation station currently deployed with create2 on Optimism and Optimism Goerli `0xEE36eaaD94d1Cc1d0eccaDb55C38bFfB6Be06C77`.
...@@ -172,7 +167,7 @@ The deployment address for the attestation station currently deployed with creat ...@@ -172,7 +167,7 @@ The deployment address for the attestation station currently deployed with creat
import { ATTESTATION_STATION_ADDRESS } from '@eth-optimism/atst' import { ATTESTATION_STATION_ADDRESS } from '@eth-optimism/atst'
``` ```
### `abi` #### `abi`
The abi of the attestation station contract The abi of the attestation station contract
...@@ -180,7 +175,7 @@ The abi of the attestation station contract ...@@ -180,7 +175,7 @@ The abi of the attestation station contract
import { abi } from '@eth-optimism/atst' import { abi } from '@eth-optimism/atst'
``` ```
### `createKey` #### `createKey`
`createKey` hashes keys longer than 31 bytes, because the atst key size is limited to 32 bytes. `createKey` hashes keys longer than 31 bytes, because the atst key size is limited to 32 bytes.
...@@ -196,7 +191,7 @@ createKey will keep the key as is if it is shorter than 32 bytes and otherwise r ...@@ -196,7 +191,7 @@ createKey will keep the key as is if it is shorter than 32 bytes and otherwise r
### `getEvents` #### `getEvents`
Use `getEvents` to get attestation events using a provider and filters. Use `getEvents` to get attestation events using a provider and filters.
...@@ -215,14 +210,14 @@ const events = await getEvents({ ...@@ -215,14 +210,14 @@ const events = await getEvents({
Set `key`, `about`, `creator`, or `value` to `null` to not filter that value. Set `key`, `about`, `creator`, or `value` to `null` to not filter that value.
### `parseAddress` #### `parseAddress`
Turn bytes into an address. Turn bytes into an address.
**Note:** `readAttestation` and `readAttestations` already do this for you. **Note:** `readAttestation` and `readAttestations` already do this for you.
This is only needed if talking to the contracts directly, or through a different library. This is only needed if talking to the contracts directly, or through a different library.
### `parseBool` #### `parseBool`
Turn bytes into a boolean value. Turn bytes into a boolean value.
...@@ -230,7 +225,7 @@ Turn bytes into a boolean value. ...@@ -230,7 +225,7 @@ Turn bytes into a boolean value.
This is only needed if talking to the contracts directly, or through a different library. This is only needed if talking to the contracts directly, or through a different library.
### `parseNumber` #### `parseNumber`
Turn bytes into a number. Turn bytes into a number.
...@@ -238,7 +233,7 @@ Turn bytes into a number. ...@@ -238,7 +233,7 @@ Turn bytes into a number.
This is only needed if talking to the contracts directly, or through a different library. This is only needed if talking to the contracts directly, or through a different library.
### `parseString` #### `parseString`
Turn bytes into a string. Turn bytes into a string.
...@@ -246,7 +241,7 @@ Turn bytes into a string. ...@@ -246,7 +241,7 @@ Turn bytes into a string.
This is only needed if talking to the contracts directly, or through a different library. This is only needed if talking to the contracts directly, or through a different library.
### `stringifyAttestationBytes` #### `stringifyAttestationBytes`
Stringifys an attestation into raw bytes. Stringifys an attestation into raw bytes.
...@@ -261,6 +256,20 @@ const bigNumberAttestation = stringifyAttestationBytes( ...@@ -261,6 +256,20 @@ const bigNumberAttestation = stringifyAttestationBytes(
**Note:** `writeAttestation` already does this for you so this is only needed if using a library other than the attestation station. **Note:** `writeAttestation` already does this for you so this is only needed if using a library other than the attestation station.
### React API
For react hooks we recomend using the [wagmi cli](https://wagmi.sh/cli/getting-started) with the [etherscan plugin](https://wagmi.sh/cli/plugins/etherscan) and [react plugin](https://wagmi.sh/cli/plugins/react) to automatically generate react hooks around the attestation station.
Use `createKey` and `createValue` to convert your raw keys and values into bytes that can be used in the attestation station contract calls.
Use `parseString`, `parseBool`, `parseAddress` and `parseNumber` to convert values returned by attestation station to their correct data type.
For convenience we also export the hooks here:
- `useAttestationStationAttestation` - Reads attestations with useContractRead
- `useAttestationStationVersion` - Reads attestation version
- `useAttestationStationAttest` - Wraps useContractWrite with attestation station abi calling attest
- `usePrepareAttestationStationAttest` - Wraps usePrepare with attestation station abi calling attest
- `useAttestationStationAttestationCreatedEvent` - Wraps useContractEvents for Created events
## Tutorial ## Tutorial
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment