-
Notifications
You must be signed in to change notification settings - Fork 11
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:
- Install the CLI package for React
npx create-react-app my-app - cd into the project
- run
npm i @tokenscript/token-negotiatorto install the token negotiator. - 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;