@f8n/foundationkit-hooks
TypeScript icon, indicating that this package has built-in type declarations

0.0.1-alpha.7 • Public • Published

FoundationKit - Hooks

A set of React hooks to interact with Foundation's NFT Market Protocol. Foundation's Marketplace protocol and these hooks support Auctions, Buy Nows and Offers.

Installation

yarn add @foundationkit/hooks

Getting Started

Wrap the top level of your application in the FoundationKit Provider

import { Provider } from '@foundationkit/hooks';

export default function App() {
  return (
    <Provider>
      <Component />
    </Provider>
  );
}

Then you can use any of the hooks in the rest of your app, all of the hooks require a provider or signer, we recommend the excellent wagmi library but you could also use Ethers.js as well.

import { useProvider } from 'wagmi';
import { useMarketInfo } from '@foundationkit/hooks';

function App() {
  const provider = useProvider();

  const { data } = useMarketInfo({
    provider,
    contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    tokenId: 8,
  });

  return <div></div>;
}

Setting the network

Foundations Market contracts are currently deployed to Mainnet and Göerli on Ethereum. To set the network being used you need to configure the provider being passed into the hooks.

With Ethers.js

// Mainnet provider
const provider = new ethers.providers.JsonRpcProvider(
  'https://ethereum-node.com',
  'mainnet'
);

// This will now be connected to mainnet information
const { data, isLoading } = useMarketInfo({
  provider,
  contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
  tokenId: 8,
});

Examples

Displaying market information

Most times when displaying an NFT you will want to show information about its current market state, this could be its current reserve price, Buy Now price, active offers and if its currently in a live auction.

To do this you can use the useMarketInfo hook as shown below.

const provider = new ethers.providers.JsonRpcProvider(
  'https://ethereum-node.com',
  'mainnet'
);

export default function NFT() {
  const { data, isLoading } = useMarketInfo({
    provider,
    contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    tokenId: 8,
  });

  const hasAuction = data?.auction;
  const isAuctionLive = data?.auction?.isAuctionLive;

  return (
    <div>
      {hasAuction && (
        <div>
          <p>{data?.auction?.amount.formatted}ETH</p>
          {isAuctionLive && <p>Ends at {data?.auction?.endsAt}</p>}
        </div>
      )}
    </div>
  );
}

Placing bids

Once you have market information you will likely want to encourage users to buy the works displayed. If the NFT has a reserve price set you can prompt the user to place a bid.

const provider = new ethers.providers.JsonRpcProvider(
  'https://ethereum-node.com',
  'mainnet'
);

export default function NFT() {
  const contractAddress = '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295';
  const tokenId = 8;

  const { data: signer } = useSigner();

  const { data, isLoading } = useMarketInfo({
    provider,
    contractAddress,
    tokenId,
  });

  const [inputAmount, setInputAmount] = useState('');

  const { data: sendBidTx, sendBid } = useSendBid({
    signer,
    contractAddress,
    tokenId,
    amount: inputAmount,
  });

  const handleChange = (e) => {
    const value = e.target.value;
    setInputAmount(value);
  };

  const handlePlaceBid = () => {
    sendBid();
  };

  const hasAuction = data?.auction;
  const isAuctionLive = data?.auction?.isAuctionLive;

  return (
    <div>
      {hasAuction && (
        <div>
          <p>{data?.auction?.amount.formatted}ETH</p>
          {isAuctionLive && <p>Ends at {data?.auction?.endsAt}</p>}
          <input onChange={handleChange} value={inputAmount} />
          <button type="button" onClick={handlePlaceBid}>
            Place Bid
          </button>
        </div>
      )}
    </div>
  );
}

Using Buy Now

As well as reserve auctions Foundation also offers Buy Now's that allows users to instantly purchase a piece for a set price.

const provider = new ethers.providers.JsonRpcProvider(
  'https://ethereum-node.com',
  'mainnet'
);

export default function NFT() {
  const contractAddress = '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295';
  const tokenId = 8;

  const { data: signer } = useSigner();

  const { data, isLoading } = useMarketInfo({
    provider,
    contractAddress,
    tokenId,
  });

  const { data: sendBuyNowTx, sendBuyNow } = useSendBuyNow({
    signer,
    contractAddress,
    tokenId,
  });

  const handleChange = (e) => {
    const value = e.target.value;
    setInputAmount(value);
  };

  const handleBuyNow = () => {
    sendBuyNow();
  };

  const hasBuyNow = marketData?.buyNow;

  return (
    <div>
      {hasBuyNow && (
        <div>
          <p>Buy now for {marketData?.buyNow?.amount}ETH</p>
          <button type="button" onClick={handleBuyNow}>
            Buy Now
          </button>
        </div>
      )}
    </div>
  );
}

Sending offers

Sometimes you might not have a price in mind for a NFT and so Reserve Auctions and Buy Now are not the most suitable tool. With Foundation we also allow a potential buyer to send an offer for the NFT, if the current owner wishes to sell they may accept the offer otherwise it will expire in 24 hours.

const provider = new ethers.providers.JsonRpcProvider(
  'https://ethereum-node.com',
  'mainnet'
);

export default function NFT() {
  const contractAddress = '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295';
  const tokenId = 8;

  const { data: signer } = useSigner();

  const { data, isLoading } = useMarketInfo({
    provider,
    contractAddress,
    tokenId,
  });

  const [inputAmount, setInputAmount] = useState('');

  const { data: sendOfferTx, sendOffer } = useSendOffer({
    signer,
    contractAddress,
    tokenId,
    amount: inputAmount,
  });

  const handleChange = (e) => {
    const value = e.target.value;
    setInputAmount(value);
  };

  const handleSendOffer = () => {
    sendOffer();
  };

  const hasOffer = data?.offer;

  return (
    <div>
      {hasOffer && (
        <div>
          <p>Current offer: {data?.offer?.amount} ETH</p>
          <p>Offer expires at {data?.offer?.offerExpiresAt}</p>
        </div>
      )}
      <input onChange={handleChange} value={inputAmount} />
      <button type="button" onClick={handleSendOffer}>
        Send offer
      </button>
    </div>
  );
}

API

useMarketInfo

Hook for accessing a NFT's market information.

import { useMarketInfo } from '@foundationkit/hooks';

Usage

An Provider must be passed in from either a library like wagmi or ethers.js.

import { useMarketInfo } from '@foundationkit/hooks';

function App() {
  const { data, isLoading } = useMarketInfo({
    provider,
    contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    tokenId: 8,
  });
}

Return Value

{
  ownerAddress: string;
  isInEscrow: boolean;
  auction?: {
    isAuctionLive: boolean;
    highestBidderAddress: string;
    endsAt: number;
    currentBidAmount: {
      value: BigNumber;
      formatted: string;
    }
    id: number;
    link: string;
  }
  buyNow?: {
    amount: {
      value: BigNumber;
      formatted: string;
    }
    link: string;
  }
  offer?: {
    amount: {
      value: BigNumber;
      formatted: string;
    }
    offererAddress: string;
    offerExpiresAt: number;
    link: string;
  }
}

Configuration

provider (required)

An Ethereum Provider must be provided from a library like wagmi or ethers.js.

import { useMarketInfo } from '@foundationkit/hooks';
import { useProvider } from 'wagmi';

function App() {
  const provider = useProvider();
  const marketInfo = useMarketInfo({
    provider,
    // contractAddress: '0x553B96a33b06ad8aaAd53BfeA1E8CD04417E0A53',
    // tokenId: 2,
  });
}
contractAddress (required)

A valid ethereum address for the smart contract of the NFT you are querying

import { useMarketInfo } from '@foundationkit/hooks';

function App() {
  const marketInfo = useMarketInfo({
    //  provider,
    contractAddress: '0x553B96a33b06ad8aaAd53BfeA1E8CD04417E0A53',
    // tokenId: 2,
  });
}
tokenId (required)

A valid token ID of the NFT you are querying.

import { useMarketInfo } from '@foundationkit/hooks';

function App() {
  const marketInfo = useMarketInfo({
    // provider,
    // contractAddress: '0x553B96a33b06ad8aaAd53BfeA1E8CD04417E0A53',
    tokenId: 2,
  });
}

useSendBid

Hook for placing a bid for a NFT that is currently in escrow of the Foundation Market contract.

import { useSendBid } from '@foundationkit/hooks';

Usage

An Signer must be passed in from either a library like wagmi or ethers.js.

import { useSendBid } from '@foundationkit/hooks';

function App() {
  const { data, isLoading, sendBid } = useSendBid({
    signer,
    contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    tokenId: 8,
    amount: '1.1',
  });
}

Return Value

{
  data?: TransactionResponse
  error?: Error
  isError: boolean
  isIdle: boolean
  isLoading: boolean
  isSuccess: boolean
  sendBid: (args?: SendBidArgs) => void
  sendBidAsync: (args?: SendBidArgs) => Promise<TransactionResponse>
  reset: () => void
  status: 'idle' | 'error' | 'loading' | 'success'
}

Configuration

signer (required)

An Ethereum Signer must be provided from a library like wagmi or ethers.js.

import { useSendBid } from '@foundationkit/hooks';
import { useSigner } from 'wagmi';

function App() {
  const signer = useSigner();
  const sendBid = useSendBid({
    signer,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
    // amount: '1.1',
  });
}
contractAddress (required)

A valid ethereum address for the smart contract of the NFT you are placing a bid on.

import { useSendBid } from '@foundationkit/hooks';

function App() {
  const sendBid = useSendBid({
    // signer,
    contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
    // amount: '1.1',
  });
}
tokenId (required)

A valid token ID of the NFT you are placing a bid on.

import { useSendBid } from '@foundationkit/hooks';

function App() {
  const sendBid = useSendBid({
    // signer,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    tokenId: 8,
    // amount: '1.1',
  });
}
amount (required)

A string value representing the bid amount you are placing, it is read as eth.

import { useSendBid } from '@foundationkit/hooks';

function App() {
  const sendBid = useSendBid({
    // signer,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
    amount: '1.1',
  });
}
referrer

A valid Ethereum address that will receive a referral fee of 1% of the sale price, if this NFT is bought via this hook. Learn more about referrals

import { useSendBid } from '@foundationkit/hooks';

function App() {
  const sendBid = useSendBid({
    referrer: '0x165CD37b4C644C2921454429E7F9358d18A45e14',
  });
}
gasMargin

By default we add a 10% gas margin to ensure tx's are processed (a good default to mitigate edge cases and ensuring there is a gas buffer), you can override this by passing a number that represents a % of the original gas estimation.

import { useSendBid } from '@foundationkit/hooks';

function App() {
  const sendBid = useSendBid({
    // Will send 15% more gas, based on the estimate gas calculation
    gasMargin: 15,
  });
}

useSendBuyNow

Hook for buying at a Buy Now price for a NFT that is currently in escrow of the Foundation Market contract.

import { useSendBuyNow } from '@foundationkit/hooks';

Usage

An Signer must be passed in from either a library like wagmi or ethers.js.

import { useSendBuyNow } from '@foundationkit/hooks';

function App() {
  const { data, isLoading, sendBuyNow } = useSendBuyNow({
    signer,
    contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    tokenId: 8,
  });
}

Return Value

{
  data?: TransactionResponse
  error?: Error
  isError: boolean
  isIdle: boolean
  isLoading: boolean
  isSuccess: boolean
  sendBid: (args?: SendBuyNowArgs) => void
  sendBidAsync: (args?: SendBuyNowArgs) => Promise<TransactionResponse>
  reset: () => void
  status: 'idle' | 'error' | 'loading' | 'success'
}

Configuration

signer (required)

An Ethereum Signer must be provided from a library like wagmi or ethers.js.

import { useSendBuyNow } from '@foundationkit/hooks';
import { useSigner } from 'wagmi';

function App() {
  const signer = useSigner();
  const sendBuyNow = useSendBuyNow({
    signer,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
  });
}
contractAddress (required)

A valid ethereum address for the smart contract of the NFT you are buying.

import { useSendBuyNow } from '@foundationkit/hooks';

function App() {
  const sendBuyNow = useSendBuyNow({
    // signer,
    contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
  });
}
tokenId (required)

A valid token ID of the NFT you are buying.

import { useSendBuyNow } from '@foundationkit/hooks';

function App() {
  const sendBuyNow = useSendBuyNow({
    //  signer,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    tokenId: 8,
  });
}
referrer

A valid Ethereum address that will receive a referral fee of 1% of the sale price, if this NFT is bought via this hook. Learn more about referrals

import { useSendBuyNow } from '@foundationkit/hooks';

function App() {
  const sendBuyNow = useSendBuyNow({
    // signer,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
    referrer: '0x165CD37b4C644C2921454429E7F9358d18A45e14',
  });
}
gasMargin

By default we add a 10% gas margin to ensure tx's are processed (a good default to mitigate edge cases and ensuring there is a gas buffer), you can override this by passing a number that represents a % of the original gas estimation.

import { useSendBuyNow } from '@foundationkit/hooks';

function App() {
  const sendBuyNow = useSendBuyNow({
    // signer,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
    // Will send 15% more gas, based on the estimate gas calculation
    gasMargin: 15,
  });
}

useSendOffer

Hook for placing an offer on an NFT.

import { useSendOffer } from '@foundationkit/hooks';

Usage

An Signer must be passed in from either a library like wagmi or ethers.js.

import { useSendOffer } from '@foundationkit/hooks';

function App() {
  const { data, isLoading, sendOffer } = useSendOffer({
    signer,
    contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    tokenId: 8,
    amount: '1.1',
  });
}

Return Value

{
  data?: TransactionResponse
  error?: Error
  isError: boolean
  isIdle: boolean
  isLoading: boolean
  isSuccess: boolean
  sendBid: (args?: SendOfferArgs) => void
  sendBidAsync: (args?: SendOfferArgs) => Promise<TransactionResponse>
  reset: () => void
  status: 'idle' | 'error' | 'loading' | 'success'
}

Configuration

signer (required)

An Ethereum Signer must be provided from a library like wagmi or ethers.js.

import { useSendOffer } from '@foundationkit/hooks';
import { useSigner } from 'wagmi';

function App() {
  const signer = useSigner();
  const sendOffer = useSendOffer({
    signer,
    // contractAddress: '0x553B96a33b06ad8aaAd53BfeA1E8CD04417E0A53',
    // tokenId: 2,
    // amount: '1.1',
  });
}
contractAddress (required)

A valid ethereum address for the smart contract of the NFT you are making an offer on.

import { useSendOffer } from '@foundationkit/hooks';

function App() {
  const sendOffer = useSendOffer({
    // signer,
    contractAddress: '0x553B96a33b06ad8aaAd53BfeA1E8CD04417E0A53',
    // tokenId: 2,
    // amount: '1.1',
  });
}
tokenId (required)

A valid token ID of the NFT you are making an offer on.

import { useSendOffer } from '@foundationkit/hooks';

function App() {
  const sendOffer = useSendOffer({
    // signer,
    // contractAddress: '0x553B96a33b06ad8aaAd53BfeA1E8CD04417E0A53',
    tokenId: 2,
    // amount: '1.1',
  });
}
amount (required)

A string value representing the offer amount, it is read as eth.

import { useSendOffer } from '@foundationkit/hooks';

function App() {
  const sendOffer = useSendOffer({
    // signer,
    // contractAddress: '0x553B96a33b06ad8aaAd53BfeA1E8CD04417E0A53',
    // tokenId: 2,
    amount: '1.1',
  });
}
referrer

A valid Ethereum address that will receive a referral fee of 1% of the sale price, if this NFT is bought via this hook. Learn more about referrals

import { useSendOffer } from '@foundationkit/hooks';

function App() {
  const sendOffer = useSendOffer({
    // signer,
    // contractAddress: '0x553B96a33b06ad8aaAd53BfeA1E8CD04417E0A53',
    // tokenId: 2,
    // amount: '1.1',
    referrer: '0x165CD37b4C644C2921454429E7F9358d18A45e14',
  });
}
gasMargin

By default we add a 10% gas margin to ensure tx's are processed (a good default to mitigate edge cases and ensuring there is a gas buffer), you can override this by passing a number that represents a % of the original gas estimation.

import { useSendOffer } from '@foundationkit/hooks';

function App() {
  const sendOffer = useSendOffer({
    // signer,
    // contractAddress: '0x553B96a33b06ad8aaAd53BfeA1E8CD04417E0A53',
    // tokenId: 2,
    // amount: '1.1',
    // Will send 15% more gas, based on the estimate gas calculation
    gasMargin: 15,
  });
}

useLastSoldPrice

Hook for fetching the last sold price of an NFT within Foundation's Market.

import { useLastSoldPrice } from '@foundationkit/hooks';

Usage

An Provider must be passed in from either a library like wagmi or ethers.js.

import { useLastSoldPrice } from '@foundationkit/hooks';

function App() {
  const { data, isLoading } = useLastSoldPrice({
    provider,
    contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    tokenId: 8,
  });
}

Return Value

{
  value: BigNumber;
  formatted: string;
}

Configuration

provider (required)

An Ethereum Provider must be provided from a library like wagmi or ethers.js.

import { useLastSoldPrice } from '@foundationkit/hooks';
import { useProvider } from 'wagmi';

function App() {
  const provider = useProvider();
  const lastSoldPrice = useLastSoldPrice({
    provider,
    // contractAddress: '0x553B96a33b06ad8aaAd53BfeA1E8CD04417E0A53',
    // tokenId: 2,
  });
}
contractAddress (required)

A valid ethereum address for the smart contract of the NFT you are fetching the last sold price for.

import { useLastSoldPrice } from '@foundationkit/hooks';

function App() {
  const lastSoldPrice = useLastSoldPrice({
    // provider,
    contractAddress: '0x553B96a33b06ad8aaAd53BfeA1E8CD04417E0A53',
    // tokenId: 2,
  });
}
tokenId (required)

A valid token ID of the NFT you are fetching the last sold price for.

import { useLastSoldPrice } from '@foundationkit/hooks';

function App() {
  const lastSoldPrice = useLastSoldPrice({
    // provider,
    // contractAddress: '0x553B96a33b06ad8aaAd53BfeA1E8CD04417E0A53',
    tokenId: 2,
  });
}

useGetApproval

Hook for checking if an address has approved Foundation's market contract.

import { useGetApproval } from '@foundationkit/hooks';

Usage

A Provider must be passed in from either a library like wagmi or ethers.js.

import { useGetApproval } from '@foundationkit/hooks';

function App() {
  const { data, isLoading } = useGetApproval({
    provider,
    contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    ownerAddress: '0x2ae5f36c77a736f76d61f3eec06f12caf2963fd6',
  });
}

Return Value

isApproved: boolean;

Configuration

provider (required)

An Ethereum Provider must be provided from a library like wagmi or ethers.js.

import { useGetApproval } from '@foundationkit/hooks';
import { useProvider } from 'wagmi';

function App() {
  const provider = useProvider();
  const getApproval = useGetApproval({
    provider,
    // contractAddress: '0x553B96a33b06ad8aaAd53BfeA1E8CD04417E0A53',
    // ownerAddress: '0x2ae5f36c77a736f76d61f3eec06f12caf2963fd6',
  });
}
contractAddress (required)

A valid ethereum address for the smart contract of the NFT you are checking is approved.

import { useGetApproval } from '@foundationkit/hooks';

function App() {
  const getApproval = useGetApproval({
    // provider,
    contractAddress: '0x553B96a33b06ad8aaAd53BfeA1E8CD04417E0A53',
    // ownerAddress: '0x2ae5f36c77a736f76d61f3eec06f12caf2963fd6',
  });
}
ownerAddress (required)

A valid ethereum address for the user who has provided approval.

import { useGetApproval } from '@foundationkit/hooks';

function App() {
  const getApproval = useGetApproval({
    // provider,
    // contractAddress: '0x553B96a33b06ad8aaAd53BfeA1E8CD04417E0A53',
    ownerAddress: '0x2ae5f36c77a736f76d61f3eec06f12caf2963fd6',
  });
}

useSetApproval

Hook for setting approval for the Foundation Market contract to perform actions on an NFT you own.

import { useSetApproval } from '@foundationkit/hooks';

Usage

An Signer must be passed in from either a library like wagmi or ethers.js.

import { useSetApproval } from '@foundationkit/hooks';

function App() {
  const { data, isLoading, setApproval } = useSetApproval({
    signer,
    contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
  });
}

Return Value

{
  data?: TransactionResponse
  error?: Error
  isError: boolean
  isIdle: boolean
  isLoading: boolean
  isSuccess: boolean
  setApproval: (args?: SetApprovalArgs) => void
  setApprovalAsync: (args?: SetApprovalArgs) => Promise<TransactionResponse>
  reset: () => void
  status: 'idle' | 'error' | 'loading' | 'success'
}

Configuration

signer (required)

An Ethereum Signer must be provided from a library like wagmi or ethers.js.

import { useSetApproval } from '@foundationkit/hooks';
import { useSigner } from 'wagmi';

function App() {
  const signer = useSigner();
  const setApproval = useSetApproval({
    signer,
    // contractAddress: '0x553B96a33b06ad8aaAd53BfeA1E8CD04417E0A53',
  });
}
contractAddress (required)

A valid ethereum address for the smart contract of the NFT you would like to approve.

import { useSetApproval } from '@foundationkit/hooks';

function App() {
  const setApproval = useSetApproval({
    // signer,
    contractAddress: '0x553B96a33b06ad8aaAd53BfeA1E8CD04417E0A53',
  });
}
gasMargin

By default we add a 10% gas margin to ensure tx's are processed (a good default to mitigate edge cases and ensuring there is a gas buffer), you can override this by passing a number that represents a % of the original gas estimation.

import { useSetApproval } from '@foundationkit/hooks';

function App() {
  const setApproval = useSetApproval({
    // signer,
    // contractAddress: '0x553B96a33b06ad8aaAd53BfeA1E8CD04417E0A53',
    // Will send 15% more gas, based on the estimate gas calculation
    gasMargin: 15,
  });
}

useSetReserveAuction

Hook for creating a reserve auction & setting a reserve price on Foundation's market contract.

import { useSetReserveAuction } from '@foundationkit/hooks';

Usage

An Signer must be passed in from either a library like wagmi or ethers.js.

import { useSetReserveAuction } from '@foundationkit/hooks';

function App() {
  const { data, isLoading, setReserveAuction } = useSetReserveAuction({
    signer,
    contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    tokenId: 8,
    amount: '1.1',
  });
}

Return Value

{
  data?: TransactionResponse
  error?: Error
  isError: boolean
  isIdle: boolean
  isLoading: boolean
  isSuccess: boolean
  setReserveAuction: (args?: SetReserveAuctionArgs) => void
  setReserveAuctionAsync: (args?: SetReserveAuctionArgs) => Promise<TransactionResponse>
  reset: () => void
  status: 'idle' | 'error' | 'loading' | 'success'
}

Configuration

signer (required)

An Ethereum Signer must be provided from a library like wagmi or ethers.js.

import { useSetReserveAuction } from '@foundationkit/hooks';
import { useSigner } from 'wagmi';

function App() {
  const signer = useSigner();
  const setReserveAuction = useSetReserveAuction({
    signer,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
    // amount: '1.1',
  });
}
contractAddress (required)

A valid ethereum address for the smart contract of the NFT you are listing in the auction.

import { useSetReserveAuction } from '@foundationkit/hooks';

function App() {
  const setReserveAuction = useSetReserveAuction({
    // signer,
    contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
    // amount: '1.1',
  });
}
tokenId (required)

A valid token ID of the NFT you are listing in the auction.

import { useSetReserveAuction } from '@foundationkit/hooks';

function App() {
  const setReserveAuction = useSetReserveAuction({
    // signer,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    tokenId: 8,
    // amount: '1.1',
  });
}
amount (required)

A string value representing the reserve price for the NFT being listed.

import { useSetReserveAuction } from '@foundationkit/hooks';

function App() {
  const setReserveAuction = useSetReserveAuction({
    // signer,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
    amount: '1.1',
  });
}
gasMargin

By default we add a 10% gas margin to ensure tx's are processed (a good default to mitigate edge cases and ensuring there is a gas buffer), you can override this by passing a number that represents a % of the original gas estimation.

import { useSetReserveAuction } from '@foundationkit/hooks';

function App() {
  const setReserveAuction = useSetReserveAuction({
    // signer,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
    // Will send 15% more gas, based on the estimate gas calculation
    gasMargin: 15,
  });
}

useSetBuyNow

Hook for listing an NFT with a Buy Now price.

import { useSetBuyNow } from '@foundationkit/hooks';

Usage

An Signer must be passed in from either a library like wagmi or ethers.js.

import { useSetBuyNow } from '@foundationkit/hooks';

function App() {
  const { data, isLoading, setBuyNow } = useSetBuyNow({
    signer,
    contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    tokenId: 8,
    amount: '1.1',
  });
}

Return Value

{
  data?: TransactionResponse
  error?: Error
  isError: boolean
  isIdle: boolean
  isLoading: boolean
  isSuccess: boolean
  setBuyNow: (args?: SetBuyNowArgs) => void
  setBuyNowAsync: (args?: SetBuyNowArgs) => Promise<TransactionResponse>
  reset: () => void
  status: 'idle' | 'error' | 'loading' | 'success'
}

Configuration

signer (required)

An Ethereum Signer must be provided from a library like wagmi or ethers.js.

import { useSetBuyNow } from '@foundationkit/hooks';
import { useSigner } from 'wagmi';

function App() {
  const signer = useSigner();
  const setBuyNow = useSetBuyNow({
    signer,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
    // amount: '1.1',
  });
}
contractAddress (required)

A valid ethereum address for the smart contract of the NFT you are listing with a Buy Now price.

import { useSetBuyNow } from '@foundationkit/hooks';

function App() {
  const setBuyNow = useSetBuyNow({
    // signer,
    contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
    // amount: '1.1',
  });
}
tokenId (required)

A valid token ID of the NFT you are listing with a Buy Now price.

import { useSetBuyNow } from '@foundationkit/hooks';

function App() {
  const setBuyNow = useSetBuyNow({
    // signer,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    tokenId: 8,
    // amount: '1.1',
  });
}
amount (required)

A string value representing the Buy Now price for the NFT being listed.

import { useSetBuyNow } from '@foundationkit/hooks';

function App() {
  const setBuyNow = useSetBuyNow({
    // signer,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
    amount: '1.1',
  });
}
gasMargin

By default we add a 10% gas margin to ensure tx's are processed (a good default to mitigate edge cases and ensuring there is a gas buffer), you can override this by passing a number that represents a % of the original gas estimation.

import { useSetBuyNow } from '@foundationkit/hooks';

function App() {
  const setBuyNow = useSetBuyNow({
    // signer,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
    // Will send 15% more gas, based on the estimate gas calculation
    gasMargin: 15,
  });
}

useCancelBuyNow

Hook to cancel a Buy Now listing.

import { useCancelBuyNow } from '@foundationkit/hooks';

Usage

An Signer must be passed in from either a library like wagmi or ethers.js.

import { useCancelBuyNow } from '@foundationkit/hooks';

function App() {
  const { data, isLoading, cancelBuyNow } = useCancelBuyNow({
    signer,
    contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    tokenId: 8,
  });
}

Return Value

{
  data?: TransactionResponse
  error?: Error
  isError: boolean
  isIdle: boolean
  isLoading: boolean
  isSuccess: boolean
  cancelBuyNow: (args?: CancelBuyNowArgs) => void
  cancelBuyNowAsync: (args?: CancelBuyNowArgs) => Promise<TransactionResponse>
  reset: () => void
  status: 'idle' | 'error' | 'loading' | 'success'
}

Configuration

signer (required)

An Ethereum Signer must be provided from a library like wagmi or ethers.js.

import { useCancelBuyNow } from '@foundationkit/hooks';
import { useSigner } from 'wagmi';

function App() {
  const signer = useSigner();
  const cancelBuyNow = useCancelBuyNow({
    signer,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
  });
}
contractAddress (required)

A valid ethereum address for the smart contract of the NFT you are cancelling the listing for.

import { useCancelBuyNow } from '@foundationkit/hooks';

function App() {
  const cancelBuyNow = useCancelBuyNow({
    // signer,
    contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
  });
}
tokenId (required)

A valid token ID of the NFT you are cancelling the listing for.

import { useCancelBuyNow } from '@foundationkit/hooks';

function App() {
  const cancelBuyNow = useCancelBuyNow({
    // signer,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    tokenId: 8,
  });
}
gasMargin

By default we add a 10% gas margin to ensure tx's are processed (a good default to mitigate edge cases and ensuring there is a gas buffer), you can override this by passing a number that represents a % of the original gas estimation.

import { useCancelBuyNow } from '@foundationkit/hooks';

function App() {
  const cancelBuyNow = useCancelBuyNow({
    // signer,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
    // Will send 15% more gas, based on the estimate gas calculation
    gasMargin: 15,
  });
}

useCancelReserveAuction

Hook to cancel a Reserve auction liting. This will only work if the auction has not started yet.

import { useCancelReserveAuction } from '@foundationkit/hooks';

Usage

An Signer must be passed in from either a library like wagmi or ethers.js.

import { useCancelReserveAuction } from '@foundationkit/hooks';

function App() {
  const { data, isLoading, cancelReserveAuction } = useCancelReserveAuction({
    signer,
    contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    tokenId: 8,
  });
}

Return Value

{
  data?: TransactionResponse
  error?: Error
  isError: boolean
  isIdle: boolean
  isLoading: boolean
  isSuccess: boolean
  cancelReserveAuction: (args?: CancelReserveAuctionArgs) => void
  cancelReserveAuctionAsync: (args?: CancelReserveAuctionArgs) => Promise<TransactionResponse>
  reset: () => void
  status: 'idle' | 'error' | 'loading' | 'success'
}

Configuration

signer (required)

An Ethereum Signer must be provided from a library like wagmi or ethers.js.

import { useCancelReserveAuction } from '@foundationkit/hooks';
import { useSigner } from 'wagmi';

function App() {
  const signer = useSigner();
  const cancelReserveAuction = useCancelReserveAuction({
    signer,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
  });
}
contractAddress (required)

A valid ethereum address for the smart contract of the NFT you are cancelling the listing for.

import { useCancelReserveAuction } from '@foundationkit/hooks';

function App() {
  const cancelReserveAuction = useCancelReserveAuction({
    // signer,
    contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
  });
}
tokenId (required)

A valid token ID of the NFT you are cancelling the listing for.

import { useCancelReserveAuction } from '@foundationkit/hooks';

function App() {
  const cancelReserveAuction = useCancelReserveAuction({
    // signer,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    tokenId: 8,
  });
}
gasMargin

By default we add a 10% gas margin to ensure tx's are processed (a good default to mitigate edge cases and ensuring there is a gas buffer), you can override this by passing a number that represents a % of the original gas estimation.

import { useCancelReserveAuction } from '@foundationkit/hooks';

function App() {
  const cancelReserveAuction = useCancelReserveAuction({
    // signer,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
    // Will send 15% more gas, based on the estimate gas calculation
    gasMargin: 15,
  });
}

useAcceptOffer

Hook to accept an active offer on an NFT you own.

import { useAcceptOffer } from '@foundationkit/hooks';

Usage

An Signer must be passed in from either a library like wagmi or ethers.js.

import { useAcceptOffer } from '@foundationkit/hooks';

function App() {
  const { data, isLoading, acceptOffer } = useAcceptOffer({
    signer,
    contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    tokenId: 8,
    amount: '0.1',
    offererAddress: '0x7E6d171d288ecED6eB2D070D8e46Aa905b0f94aE',
  });
}

Return Value

{
  data?: TransactionResponse
  error?: Error
  isError: boolean
  isIdle: boolean
  isLoading: boolean
  isSuccess: boolean
  acceptOffer: (args?: AcceptOfferArgs) => void
  acceptOfferAsync: (args?: AcceptOfferArgs) => Promise<TransactionResponse>
  reset: () => void
  status: 'idle' | 'error' | 'loading' | 'success'
}

Configuration

signer (required)

An Ethereum Signer must be provided from a library like wagmi or ethers.js.

import { useAcceptOffer } from '@foundationkit/hooks';
import { useSigner } from 'wagmi';

function App() {
  const signer = useSigner();
  const acceptOffer = useAcceptOffer({
    signer,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
    // amount: '0.1',
    // offererAddress: '0x7E6d171d288ecED6eB2D070D8e46Aa905b0f94aE',
  });
}
contractAddress (required)

A valid ethereum address for the smart contract of the NFT you are accepting an offer for.

import { useAcceptOffer } from '@foundationkit/hooks';

function App() {
  const acceptOffer = useAcceptOffer({
    // signer,
    contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
    // amount: '0.1',
    // offererAddress: '0x7E6d171d288ecED6eB2D070D8e46Aa905b0f94aE',
  });
}
tokenId (required)

A valid token ID of the NFT you are accepting an offer for.

import { useAcceptOffer } from '@foundationkit/hooks';

function App() {
  const acceptOffer = useAcceptOffer({
    // signer,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    tokenId: 8,
    // amount: '0.1',
    // offererAddress: '0x7E6d171d288ecED6eB2D070D8e46Aa905b0f94aE',
  });
}
amount (required)

The amount the offer is for that you wish to accept. You can get this value from the useMarketInfo hook.

import { useAcceptOffer } from '@foundationkit/hooks';

function App() {
  const acceptOffer = useAcceptOffer({
    // signer,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
    amount: '0.1',
    // offererAddress: '0x7E6d171d288ecED6eB2D070D8e46Aa905b0f94aE',
  });
}
offererAddress (required)

The Ethereum address of the person making the offer. You can get this value from the useMarketInfo hook.

import { useAcceptOffer } from '@foundationkit/hooks';

function App() {
  const acceptOffer = useAcceptOffer({
    // signer,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
    // amount: '0.1',
    offererAddress: '0x7E6d171d288ecED6eB2D070D8e46Aa905b0f94aE',
  });
}
gasMargin

By default we add a 10% gas margin to ensure tx's are processed (a good default to mitigate edge cases and ensuring there is a gas buffer), you can override this by passing a number that represents a % of the original gas estimation.

import { useAcceptOffer } from '@foundationkit/hooks';

function App() {
  const acceptOffer = useAcceptOffer({
    // signer,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
    // amount: '0.1',
    // offererAddress: '0x7E6d171d288ecED6eB2D070D8e46Aa905b0f94aE',
    // Will send 15% more gas, based on the estimate gas calculation
    gasMargin: 15,
  });
}

useFinalizeReserveAuction

Hook to finalize an reserve auction, this function initiates the transfer of the NFT to the new owner and the payment amount to the seller. It can be called by anyone.

import { useFinalizeReserveAuction } from '@foundationkit/hooks';

Usage

An Signer must be passed in from either a library like wagmi or ethers.js.

import { useFinalizeReserveAuction } from '@foundationkit/hooks';

function App() {
  const { data, isLoading, finalizeReserveAuction } = useFinalizeReserveAuction(
    {
      signer,
      contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
      tokenId: 8,
    }
  );
}

Return Value

{
  data?: TransactionResponse
  error?: Error
  isError: boolean
  isIdle: boolean
  isLoading: boolean
  isSuccess: boolean
  finalizeReserveAuction: (args?: FinalizeReserveAuctionArgs) => void
  finalizeReserveAuctionAsync: (args?: FinalizeReserveAuctionArgs) => Promise<TransactionResponse>
  reset: () => void
  status: 'idle' | 'error' | 'loading' | 'success'
}

Configuration

signer (required)

An Ethereum Signer must be provided from a library like wagmi or ethers.js.

import { useFinalizeReserveAuction } from '@foundationkit/hooks';
import { useSigner } from 'wagmi';

function App() {
  const signer = useSigner();
  const finalizeReserveAuction = useFinalizeReserveAuction({
    signer,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
  });
}
contractAddress (required)

A valid ethereum address for the smart contract of the NFT you are finalizing the auction for.

import { useFinalizeReserveAuction } from '@foundationkit/hooks';

function App() {
  const finalizeReserveAuction = useFinalizeReserveAuction({
    // signer,
    contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
  });
}
tokenId (required)

A valid token ID of the NFT you are finalizing the auction for.

import { useFinalizeReserveAuction } from '@foundationkit/hooks';

function App() {
  const finalizeReserveAuction = useFinalizeReserveAuction({
    // signer,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    tokenId: 8,
  });
}
gasMargin

By default we add a 10% gas margin to ensure tx's are processed (a good default to mitigate edge cases and ensuring there is a gas buffer), you can override this by passing a number that represents a % of the original gas estimation.

import { useFinalizeReserveAuction } from '@foundationkit/hooks';

function App() {
  const finalizeReserveAuction = useFinalizeReserveAuction({
    // signer,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
    // Will send 15% more gas, based on the estimate gas calculation
    gasMargin: 15,
  });
}

useBalances

Hook for accessing an accounts ETH and FETH balances, these can be locked and available depending if offers have been placed and expired. Learn more about Marketplace balances

import { useBalances } from '@foundationkit/hooks';

Usage

An Provider must be passed in from either a library like wagmi or ethers.js.

import { useBalances } from '@foundationkit/hooks';

function App() {
  const { data, isLoading } = useBalances({
    provider,
    accountAddress: '0x61bC292750B648Fa9502f8FEBeBd806c3b484ACe',
  });
}

Return Value

{
  ensName: string;
  ethBalance: {
    value: BigNumber;
    formatted: string;
  }
  availableFethBalance: {
    value: BigNumber;
    formatted: string;
  }
  lockedFethBalance: {
    value: BigNumber;
    formatted: string;
  }
}

Configuration

provider (required)

An Ethereum Provider must be provided from a library like wagmi or ethers.js.

import { useBalances } from '@foundationkit/hooks';
import { useProvider } from 'wagmi';

function App() {
  const provider = useProvider();
  const balances = useBalances({
    provider,
    // accountAddress: '0x61bC292750B648Fa9502f8FEBeBd806c3b484ACe',
  });
}
accountAddress (required)

A valid ethereum address for the account you are looking up balances for.

import { useMarketInfo } from '@foundationkit/hooks';

function App() {
  const marketInfo = useMarketInfo({
    //  provider,
    accountAddress: '0x61bC292750B648Fa9502f8FEBeBd806c3b484ACe',
  });
}

useMintedDate

A hook for fetching the timestamp that a NFT was minted at.

import { useMintedDate } from '@foundationkit/hooks';

Usage

An Provider must be passed in from either a library like wagmi or ethers.js.

import { useMintedDate } from '@foundationkit/hooks';
import { useProvider } from 'wagmi';

function App() {
  const provider = useProvider();
  const mintedDate = useMintedDate({
    provider,
    contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    tokenId: 8,
  });
}

Return Value

mintedDate: number;

Configuration

provider (required)

An Ethereum Provider must be provided from a library like wagmi or ethers.js.

import { useMintedDate } from '@foundationkit/hooks';
import { useProvider } from 'wagmi';

function App() {
  const provider = useProvider();
  const mintedDate = useMintedDate({
    provider,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
  });
}
contractAddress (required)

A valid ethereum address for the smart contract of the NFT you are fetching the minted date for.

import { useMintedDate } from '@foundationkit/hooks';
import { useProvider } from 'wagmi';

function App() {
  const provider = useProvider();
  const mintedDate = useMintedDate({
    // provider,
    contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    // tokenId: 8,
  });
}
tokenId (required)

A valid token ID of the NFT you are fetching the minted date for.

import { useMintedDate } from '@foundationkit/hooks';
import { useProvider } from 'wagmi';

function App() {
  const provider = useProvider();
  const mintedDate = useMintedDate({
    // provider,
    // contractAddress: '0x47609b1a83B2Fc92C8AD632aE093AC61d9A85295',
    tokenId: 8,
  });
}

useWithdrawFeth

Hook to withdraw your Foundation Marketplace balance (FETH) into ETH.

import { useWithdrawFeth } from '@foundationkit/hooks';

Usage

An Signer must be passed in from either a library like wagmi or ethers.js.

import { useWithdrawFeth } from '@foundationkit/hooks';

function App() {
  const { data, isLoading, withdrawFeth } = useWithdrawFeth({
    signer,
  });
}

Return Value

{
  data?: TransactionResponse
  error?: Error
  isError: boolean
  isIdle: boolean
  isLoading: boolean
  isSuccess: boolean
  withdrawFeth: (args?: WithdrawFethArgs) => void
  withdrawFethAsync: (args?: WithdrawFethArgs) => Promise<TransactionResponse>
  reset: () => void
  status: 'idle' | 'error' | 'loading' | 'success'
}

Configuration

signer (required)

An Ethereum Signer must be provided from a library like wagmi or ethers.js.

import { useWithdrawFeth } from '@foundationkit/hooks';
import { useSigner } from 'wagmi';

function App() {
  const signer = useSigner();
  const withdrawFeth = useWithdrawFeth({
    signer,
  });
}
gasMargin

By default we add a 10% gas margin to ensure tx's are processed (a good default to mitigate edge cases and ensuring there is a gas buffer), you can override this by passing a number that represents a % of the original gas estimation.

import { useWithdrawFeth } from '@foundationkit/hooks';

function App() {
  const withdrawFeth = useWithdrawFeth({
    // signer,
    // Will send 15% more gas, based on the estimate gas calculation
    gasMargin: 15,
  });
}

Package Sidebar

Install

npm i @f8n/foundationkit-hooks

Weekly Downloads

22

Version

0.0.1-alpha.7

License

MIT

Unpacked Size

152 kB

Total Files

7

Last publish

Collaborators

  • lukebailey
  • shandysulen
  • yavor
  • sentantadmin
  • reggieag
  • matbhz
  • annacarey
  • scott-fnd
  • chriscollins
  • elpizo-f8n
  • gosseti
  • saturnial
  • nickcuso
  • hsuhanfnd