-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useMemo, useEffect } from 'react'; | |
import { RPCWeb3Provider, buildRPC } from '@compound-finance/comet-extension'; | |
export function useRPC() { | |
let rpc = useMemo(buildRPC, []); | |
useEffect(() => { | |
rpc.attachHandler() | |
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