1.5.0 • Published 10 months ago

@futureverse/signer v1.5.0

Weekly downloads
-
License
-
Repository
-
Last release
10 months ago

Futureverse Signer

Provides a signer interface with common methods for signing messages, transactions and extrinsics.

Installation

NPM:

    npm install @futureverse/signer --save

Yarn:

    yarn add @futureverse/signer

Usage

Wagmi useFutureverseSigner Hook

The example below shows how to create a hook (useFutureverseSigner) to get the signer interface from wagmi wallet client.

import { clientToSigner } from '@futureverse/signer';
import { useMemo } from 'react';
import { type Connector, useWalletClient } from 'wagmi';

/** Action to convert a Viem Client to a Futureverse Signer. */
export function useFutureverseSigner({ chainId, connector }: { chainId?: number; connector?: Connector } = {}) {
  const { data: client } = useWalletClient({ chainId, connector });

  return useMemo(() => (client ? clientToSigner(client) : undefined), [client]);
}

Signing a message

import { useCallback } from 'react';
import { useFutureverseSigner } from './useFutureverseSigner';

function MessageSignerDemo() {
  const { signer } = useFutureverseSigner();

  const signExtrinsic = useCallback(async () => {
    if (!signer) return;
    const message = 'message to sign';
    return await signer.signMessage(message);
  }, [signer]);

  // Your UI code to call signExtrinsic
  return <></>;
}

Signing a Root Network extrinsic

import { userSession } from '@futureverse/auth';
import { useTrnApi } from '@futureverse/transact-react';
import { useCallback } from 'react';
import { useFutureverseSigner } from './useFutureverseSigner';

function ExtrinsicSignerDemo() {
  const { userSession } = useAuth();
  const { trnApi } = useTrnApi();
  const { signer } = useFutureverseSigner();

  const signExtrinsic = useCallback(async () => {
    if (!signer) return;
    if (!trnApi) return;
    if (!userSession?.eoa) return;
    const collectionId = '<your collection id>';
    const numberOfTokens = 1; // How many tokens to mint
    const address = 'FuturePass or address to mint to';
    const extrinsic = trnApi.tx.nft.mint(collectionId, numberOfTokens, address);
    return await signer.signExtrinsic(trnApi, extrinsic, userSession.eoa);
  }, [signer]);

  // Your UI code to call signExtrinsic
  return <></>;
}
1.5.0

10 months ago

1.4.0

10 months ago

1.3.1

11 months ago

1.3.0

11 months ago

1.2.4

12 months ago

1.2.3

12 months ago

1.2.2

12 months ago

1.2.1

1 year ago

1.1.1-beta.0

1 year ago

1.2.0

1 year ago

1.1.0

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.6.7

1 year ago

0.6.6

1 year ago

0.6.5

1 year ago

0.6.4

1 year ago

0.6.3

1 year ago

0.6.2

1 year ago

0.6.1

1 year ago

0.6.0

1 year ago

0.5.1

1 year ago

0.5.0

1 year ago

0.4.5

1 year ago

0.4.4

1 year ago

0.4.3

1 year ago

0.4.2

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.3.0

1 year ago

0.0.1

1 year ago

0.1.0

1 year ago