0.5.0 • Published 5 days ago

@daohaus/tx-builder v0.5.0

Weekly downloads
-
License
-
Repository
github
Last release
5 days ago

@daohaus/tx-builder

This feature allows your React application to easily make transactions with all the JavaScript app lifecycle functions baked-in to trigger error and success messages, along with other cool features. Transactions are at the core of our platform, so we designed this library to provide helper utilities for this purpose.

The core element is a React Context that bundles together generic transaction calls with subgraph polling within the function. This provides lifecycle methods that we can use to control UI based on synchronized events from within the React component.

The package uses Viem.

Related packages

View on NPM

Usage

Installation

yarn add @daohaus/tx-builder

Requirements

Graph API Keys If you are trying to query for data on Etheruem Mainnet or Gnosis Chain (and more to come) you will need to provide an API key from TheGraph. Learn to get those here and here.

RPC endpoints This package makes transaction to the blockchain so you will also need to provide RPC endpoints for the chains you are targeting.

Blockchain Explorer API keys This package fetches ABIs in some instances if you are not providing the ABI in the txLego. You can provide those keys from etherscan flavored explorers if needed.

<TXBuilder
  ...
  //all other props
  chainId={'0x1'}
  graphApiKeys={{'0x1': 'some api key'}}
  rpcs={{'0x1': 'some rpc url'}}
  explorerKeys={{'0x1': 'some explorer api key'}}
>
  {children}
</TXBuilder>

How to add to you application Tx-builder uses Viem and requires you to pass a publicClient as a prop. This example shows a component wrapped in our DHConnectProvider from the @daohaus/connect package that set up a publicClient upon wallet connection.

import { TXBuilder } from '@daohaus/tx-builder';

export const SomePage = () => {
  const { publicClient } = useDHConnect();

  return (
    <TXBuilder publicClient={publicClient} chainId={'0x1'} daoId={'0xsomedaoaddress'} safeId={'0x0somedaosafeaddress'}>
      {children}
    </TXBuilder>
  );
};
Prop Name
chainIdtarget network chain id
daoIdtarget dao contract addresss
safeIdtarget dao's main treasury safe contract addresss
publicClientviem public client
appStateobject of arbitrary state data passed to the tx-builder
txLifeCycleFnscustom functions to be run on tx lifecycle moments - view here
localABIscustom abis you might want to pass to the tx-builder, these can be added in your txLego as well
rpcslist of rpc endpoints by chain id
graphApiKeyslist of graph api keys by chain id (required for mainnet and gnosis chain)
explorerKeyslist of etherscan explorer keys by chain id

Examples

TODO: link to these when the new docs app is ready.

Here is a tutorial on form and transaction building.

Here are some examples( of contract and transaction legos used in tx-builder.

How to fire a transaction

Tx Builder exposes several handy functions that can be used throughout your app. These can be accessed by importing useTxBuilder from Tx Builder:

// Anywhere in your app

import { useTxBuilder } from '@daohaus/tx-builder-feature';

...

const { fireTransaction } = useTxBuilder();

...

  fireTransaction({
    tx: ACTION_TX.SOME_TX_LEGO,
    lifeCycleFns:{
      onTxSuccess: () => {
        console.log('do something on success');
      },
    };

For a detailed example, refer to the CancelProposal.tsx our Admin App.

Building

Run nx tx-builder:build to build the library.

0.5.0

5 days ago

0.4.5

6 days ago

0.4.4

1 month ago

0.4.3

2 months ago

0.4.2

3 months ago

0.4.1

4 months ago

0.4.0

4 months ago

0.3.3

5 months ago

0.1.32

10 months ago

0.2.0-alpha.0

10 months ago

0.2.0-alpha.4

9 months ago

0.2.0-alpha.3

9 months ago

0.2.0-alpha.6

9 months ago

0.2.0-alpha.5

9 months ago

0.3.0

7 months ago

0.2.1

9 months ago

0.2.0

9 months ago

0.3.2

6 months ago

0.2.3

8 months ago

0.3.1

7 months ago

0.2.2

8 months ago

0.1.31

11 months ago

0.1.30

11 months ago

0.1.27

12 months ago

0.1.28

12 months ago

0.1.29

11 months ago

0.1.25

12 months ago

0.1.26

12 months ago

0.1.21

1 year ago

0.1.22

1 year ago

0.1.23

1 year ago

0.1.24

1 year ago

0.1.20

1 year ago

0.1.19

1 year ago

0.1.16

1 year ago

0.1.17

1 year ago

0.1.18

1 year ago

0.1.4

1 year ago

0.1.5

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

2 years ago

0.0.1

2 years ago