Skip to content

Instantly share code, notes, and snippets.


ajb413/index.js Secret

Created January 3, 2023 16:02
What would you like to do?
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