Skip to content

quick start React

Nick edited this page Apr 9, 2022 · 16 revisions

This is a small guide to install the token negotiator with React.

Using the command line / Terminal:

  1. Install the CLI package for React npx create-react-app my-app
  2. cd into the project
  3. run npm i @tokenscript/token-negotiator to install the token negotiator.
  4. Following Readme, or using this example code add the token negotiator to the project.
import React, { useState, useEffect } from 'react';
import { Client } from '@tokenscript/token-negotiator';

const App = () => {

  const [tokens, setTokens] = useState([]);

  const [proof, setProof] = useState();

  useEffect(() => {
   
  var negotiator = new negotiator.Client({ 
      /* please copy the latest example configuration from the main readme */ 
  });

  negotiator.on("tokens-selected", (tokens) => { 
    
      // selected tokens
      let selectedTokens = [];

      tokenKeys.map((token) => {

        selectedTokens.push(...tokens.selectedTokens[token].tokens);
        
      });

      setTokens(selectedTokens);

  });

  negotiator.on("token-proof", (proof) => { 
          
      // use proof
      setProof(proof);

  });

  negotiator.negotiate();

  }, []);

  return (
    <div>
      <div className="overlay-tn"></div>
    </div>
  )
}

export default App;
Clone this wiki locally