|
1 | 1 | <p align="center"> |
2 | | - <a href="http://getsumer.com"> |
3 | | - <img src="https://uploads-ssl.webflow.com/633ab0cd3a69e79d248f3b25/633abf29186753321feb30c4_sumer-logo-v1.svg" loading="lazy" width="192px" height="192px"/> |
| 2 | + <a href="https://getsumer.com"> |
| 3 | + <img src="https://sumer-public.s3.eu-west-1.amazonaws.com/sumer-logo-v1.svg" loading="lazy" width="192px" height="192px"/> |
4 | 4 | </a> |
5 | 5 | </p> |
6 | 6 |
|
7 | 7 | <h2 align="center"> |
8 | | - Sumer SDK Quickstart |
| 8 | + Sumer SDK |
9 | 9 | </h2> |
10 | 10 |
|
11 | 11 | [](https://badge.fury.io/js/sumer-sdk) |
12 | 12 |
|
13 | | -#### Sumer is the easiest way to track your dapp activity, install and integrate the sumer-sdk within few lines of code :rocket: |
| 13 | +#### Sumer is the easiest way to track your Dapp activity. Integrate _sumer-sdk_ within few lines of code. |
14 | 14 |
|
15 | | -### Install |
| 15 | +### Introduction |
| 16 | + |
| 17 | +This is an Observer Pattern-based SDK that allows users to observe Web3 Providers execution. |
| 18 | + |
| 19 | +### Quickstart |
| 20 | + |
| 21 | +#### Go to [Sumer App](https://app.getsumer.com/) |
| 22 | +Complete the sign-up process and create your Dapp to receive its _key_; copy it to use later. |
| 23 | + |
| 24 | +#### Install |
| 25 | +Add the _sumer-sdk_ package to your project: |
16 | 26 | ``` |
17 | 27 | npm i sumer-sdk |
| 28 | +yarn add sumer-sdk |
18 | 29 | ``` |
19 | 30 |
|
20 | | -#### After installing the Sumer SDK in your project and getting your dApp key from the signup process at [Sumer App](https://app.getsumer.com/), you can start using Sumer as follows: |
| 31 | +#### Initialize |
21 | 32 |
|
22 | | -* Initialize the Sumer client by wrapping the provider:<br> |
23 | 33 | ```JS |
24 | | -... |
25 | | -import { Sumer } from "sumer-sdk" |
26 | | -const dappKey = 'YOUR_DAPP_KEY' |
| 34 | +import { Sumer } from 'sumer-sdk' |
| 35 | + |
| 36 | +Sumer.init({ |
| 37 | + dappKey: 'YOUR_DAPP_KEY', |
| 38 | +}) |
| 39 | +``` |
| 40 | + |
| 41 | +#### Use |
27 | 42 |
|
28 | | -const web3provider = new ethers.providers.Web3Provider(window.ethereum, dappKey) |
| 43 | +* _web3-react_ example: |
29 | 44 |
|
30 | | -const provider = Sumer.init({ provider: web3provider, dappKey }) |
| 45 | +```JS |
| 46 | +import { Sumer } from 'sumer-sdk' |
31 | 47 |
|
32 | | -// Use the provider as usual |
33 | | -await provider.send("eth_requestAccounts", []) |
34 | | -... |
| 48 | +function getWeb3Library(provider: any): providers.Web3Provider { |
| 49 | + const library = new ethers.providers.Web3Provider(Sumer.observe(provider)) |
| 50 | + library.pollingInterval = 12000 |
| 51 | + return library |
| 52 | +} |
| 53 | + |
| 54 | +<Web3ReactProvider getLibrary={getWeb3Library}> |
| 55 | + <YourDappComponents /> |
| 56 | +</Web3ReactProvider> |
35 | 57 | ``` |
36 | 58 |
|
37 | | - * Then wrap your contracts to automatically listen for events and errors: |
38 | | - |
| 59 | +* _wagmi.sh_ example: |
| 60 | + |
39 | 61 | ```JS |
40 | | -... |
41 | | -import { Sumer } from "sumer-sdk" |
| 62 | +import { Sumer } from 'sumer-sdk' |
| 63 | + |
| 64 | +const { chains, provider, webSocketProvider } = configureChains( |
| 65 | + [mainnet], |
| 66 | + [publicProvider()], |
| 67 | +) |
| 68 | +const client = createClient({ |
| 69 | + autoConnect: true, |
| 70 | + connectors: [ |
| 71 | + new MetaMaskConnector({ chains }), |
| 72 | + ], |
| 73 | + provider: Sumer.observe(provider), |
| 74 | + webSocketProvider: Sumer.observe(webSocketProvider), |
| 75 | +}) |
| 76 | + |
| 77 | +<WagmiConfig client={client}> |
| 78 | + <YourDappComponents /> |
| 79 | +</WagmiConfig> |
| 80 | +``` |
42 | 81 |
|
43 | | -const contract = Sumer.createWrappedContract(address, abi, signerOrProvider) |
| 82 | +* _ethers_ contract example: |
| 83 | + |
| 84 | +```JS |
| 85 | +import { Sumer } from 'sumer-sdk' |
| 86 | + |
| 87 | +const contract = Sumer.contract(address, abi, chainId, signerOrProvider) |
44 | 88 |
|
45 | 89 | // Use the contract instance as usual |
46 | | -const tx = contract.myFunction(...) |
47 | | -... |
| 90 | +const tx = contract.myFunction(...) |
48 | 91 | ``` |
49 | 92 |
|
50 | | -* Integrate with [web3-react](https://github.com/Uniswap/web3-react): |
| 93 | +* Custom _observers_ example: |
51 | 94 |
|
52 | 95 | ```JS |
53 | | -... |
54 | | -import { Sumer } from "sumer-sdk" |
55 | | -const dappKey = 'YOUR_DAPP_KEY' |
56 | | - |
57 | | -// Configuration for web3-react |
58 | | -const getLibrary = (provider) => { |
| 96 | +import { Sumer, Observer, Target } from 'sumer-sdk' |
59 | 97 |
|
60 | | - const library = Sumer.init({ provider, dappKey }) |
61 | | - |
62 | | - return library |
| 98 | +class CustomObserver implements Observer { |
| 99 | + public async inspect(target: Target): Promise<void> { |
| 100 | + // Use target object as needed |
| 101 | + } |
63 | 102 | } |
64 | | - |
65 | | -// Use the Web3ReactProvider as usual |
66 | | - <Web3ReactProvider getLibrary={getLibrary}> |
67 | | - <YourDappComponents /> |
68 | | - </Web3ReactProvider> |
| 103 | +// ... |
| 104 | +const client = createClient({ |
| 105 | + autoConnect: true, |
| 106 | + connectors: [ |
| 107 | + new MetaMaskConnector({ chains }), |
| 108 | + ], |
| 109 | + provider: Sumer.observe(provider, [new CustomObserver()]), |
| 110 | +}) |
| 111 | +// ... |
69 | 112 | ``` |
70 | 113 |
|
71 | | -* If you want to use other web3 react hooks libraries, and you may have any trouble implementing it, please get in touch with us to provide you [support](https://discord.com/channels/1044217387119022080/1044252595616751676). |
| 114 | +**If you have any trouble integrating with other web3 libraries, please get in touch with us to provide you [support](https://discord.com/channels/1044217387119022080/1044252595616751676).** |
0 commit comments