1.1.3 • Published 1 year ago

near-provider v1.1.3

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Near Provider

About

near-provider is a React component which provides easy access to the NEAR protocol javascript API in Next JS and React applications.

Installation

npm install near-provider

Usage

Next JS

pages/_app.js

import { NearProvider } from "near-provider";

function MyApp({ Component, pageProps }) {
  return (
    <NearProvider>
      <Component {...pageProps} />
    </NearProvider>
  );
}

pages/index.js

import { useNear } from "near-provider";

export default function Home() {
  const { near, wallet } = useNear();

  const signIn = () => {
    wallet.requestSignIn(
      "example-contract.testnet", // contract requesting access
      "Example App", // optional
      "http://YOUR-URL.com/success", // optional
      "http://YOUR-URL.com/failure" // optional
    );
  };

  return <button onClick={signIn}>Connect</button>;
}

React

src/ParentComponent.js

import { NearProvider } from "near-provider";

export default function ParentComponent() {
  return (
    <NearProvider>
      <ChildComponent />
    </NearProvider>
  );
}

src/ChildComponent.js

import { useNear } from "near-provider";

export default function ChildComponent() {
  const { near, wallet } = useNear();

  const signIn = () => {
    wallet.requestSignIn(
      "example-contract.testnet", // contract requesting access
      "Example App", // optional
      "http://YOUR-URL.com/success", // optional
      "http://YOUR-URL.com/failure" // optional
    );
  };

  return <button onClick={signIn}>Connect</button>;
}
1.1.1

1 year ago

1.1.0

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.0.92

2 years ago

1.0.91

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago