@aptos-labs/aptos-names-connector
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

Integrate with Aptos Names Service

The Aptos Name Service provides a React UI package that offers developers a customizable button and modal to enable users to search for and mint Aptos names directly from their website.

Prerequisites

  • React project
  • Supporting dependencies installed in the root directory of your React project with npm or yarn:
    • npm install @emotion/styled @emotion/react
    • yarn add @emotion/styled @emotion/react react-copy-to-clipboard

Use Aptos Names Service Connector

  1. Open a terminal session and navigate to the root directory of your React project.
  2. Install the aptos-names-connector package using npm or yarn:
    • npm install "@aptos-labs/aptos-names-connector"
    • yarn add "@aptos-labs/aptos-names-connector"
  3. Once you have installed the package, you can import the AptosNamesConnector component and use it in your React application (by default in ./src/App.js):
    import { AptosNamesConnector } from "@aptos-labs/aptos-names-connector";
    
    function MyComponent() {
      const handleSignTransaction = async () => {
        // Handle signing of transaction
      };
    
      return (
        <AptosNamesConnector
          onSignTransaction={handleSignTransaction}
          isWalletConnected={true}
          network="mainnet"
          buttonLabel="Claim"
        />
      );
    }
    
  4. To see your changes, start a development server using npm or yarn. The following commands will open the React application in your default web browser (typically to localhost:3000):
    • npm start
    • yarn start

Configure AptosNamesConnector properties

The AptosNamesConnector component accepts the following props:

  • onSignTransaction: A required callback function that is called when the user clicks the "Mint" button in the modal. This function should handle the signing of the transaction.
  • isWalletConnected: A boolean value that indicates whether the user's wallet is connected.
  • network: A string value that specifies whether the component should connect to the mainnet or testnet.
  • buttonLabel: A string value that specifies the text to display on the button.

Customize button label and appearance

The button label can be customized by passing a string value to the buttonLabel prop. The appearance of the button in the AptosNamesConnector component can be customized to fit in your website. The button has the CSS class name of ans_connector_button:

.ans-connector-button {
  background-color: #000000;
  border: none;
  border-radius: 4px;
  color: #ffffff;
  cursor: pointer;
  font-size: 16px;
  font-weight: bold;
  padding: 12px 16px;
}

To use ans_connector_button in your React application, add import "@aptos-labs/aptos-names-connector/dist/index.css"; to the top of your App.js file and reference it with <button className="ans_connector_button"></button>

Supported networks

The AptosNamesConnector component supports both mainnet and testnet. To connect to the mainnet, set the network prop to "mainnet". To connect to the testnet, set the network prop to "testnet".

Readme

Keywords

none

Package Sidebar

Install

npm i @aptos-labs/aptos-names-connector

Weekly Downloads

74

Version

0.0.2

License

MIT

Unpacked Size

129 kB

Total Files

31

Last publish

Collaborators

  • aptos-labs