Skip to content

Commit 9d93e09

Browse files
author
Isaac Herrera
authored
Merge pull request #18 from getsumer/ih/build-refactor
Ih/build and architectural refactor
2 parents 0450323 + 7f24224 commit 9d93e09

49 files changed

Lines changed: 978 additions & 496 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/npm-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
release:
88
types: [published]
99

10-
jobs:
10+
jobs:
1111
build:
1212
runs-on: ubuntu-latest
1313
strategy:

README.md

Lines changed: 81 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,114 @@
11
<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"/>
44
</a>
55
</p>
66

77
<h2 align="center">
8-
Sumer SDK Quickstart
8+
Sumer SDK
99
</h2>
1010

1111
[![npm version](https://badge.fury.io/js/sumer-sdk.svg)](https://badge.fury.io/js/sumer-sdk)
1212

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.
1414

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:
1626
```
1727
npm i sumer-sdk
28+
yarn add sumer-sdk
1829
```
1930

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
2132

22-
* Initialize the Sumer client by wrapping the provider:<br>
2333
```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
2742

28-
const web3provider = new ethers.providers.Web3Provider(window.ethereum, dappKey)
43+
* _web3-react_ example:
2944

30-
const provider = Sumer.init({ provider: web3provider, dappKey })
45+
```JS
46+
import { Sumer } from 'sumer-sdk'
3147

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>
3557
```
3658

37-
* Then wrap your contracts to automatically listen for events and errors:
38-
59+
* _wagmi.sh_ example:
60+
3961
```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+
```
4281

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)
4488

4589
// Use the contract instance as usual
46-
const tx = contract.myFunction(...)
47-
...
90+
const tx = contract.myFunction(...)
4891
```
4992

50-
* Integrate with [web3-react](https://github.com/Uniswap/web3-react):
93+
* Custom _observers_ example:
5194

5295
```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'
5997

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+
}
63102
}
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+
// ...
69112
```
70113

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).**

jest.config.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
{
22
"preset": "ts-jest",
3-
"testEnvironment": "node",
3+
"testEnvironment": "jsdom",
44
"cacheDirectory": ".tmp/jestCache",
55
"roots": [
66
"<rootDir>/tests"
77
],
88
"moduleNameMapper": {
99
"axios": "axios/dist/node/axios.cjs"
10+
},
11+
"globals": {
12+
"ts-jest": {
13+
"tsconfig": "<rootDir>/tsconfig.test.json"
14+
},
15+
"__DEBUG_BUILD__": true
1016
}
1117
}

0 commit comments

Comments
 (0)