Skip to content

Instantly share code, notes, and snippets.


ajb413/index.js Secret

Created January 3, 2023 16:02
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ajb413/2d1a3a5449a20e9e5608a4c79268c489 to your computer and use it in GitHub Desktop.
Converting an existing React.js dapp to a Comet Extension using the shim.
import { useMemo, useEffect } from 'react';
import { RPCWeb3Provider, buildRPC } from '@compound-finance/comet-extension';
export function useRPC() {
let rpc = useMemo(buildRPC, []);
useEffect(() => {
return rpc.detachHandler;
}, [rpc]);
return rpc;
if (isEmbeddedAsCometExtension) {
provider = new RPCWeb3Provider(useRPC().sendRPC);
} else {
// Create the provider for Web3.js like you normally would
web3 = new Web3(provider);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment