Skip to content

Commit f50fa0e

Browse files
authored
Merge pull request #1531 from blocknative/release/2.20.1
Release 2.20.1 (docs)
2 parents f5dde45 + d35cd39 commit f50fa0e

File tree

33 files changed

+421
-158
lines changed

33 files changed

+421
-158
lines changed

.github/workflows/docs.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ jobs:
5151
NODE_OPTIONS: "--max_old_space_size=8192"
5252
run: yarn build
5353

54+
- name: Generate the sitemap
55+
uses: cicirello/generate-sitemap@v1
56+
with:
57+
path-to-root: docs
58+
base-url-path: https://www.onboard.blocknative.com/
59+
5460
- name: Peak at folder contents
5561
run: ls -al
5662

assets/transaction-preview.png

-37.6 KB
Loading

docs/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,15 @@
5454
},
5555
"type": "module",
5656
"dependencies": {
57+
"bnc-sdk": "^4.6.6",
5758
"@web3-onboard/coinbase": "^2.1.4",
58-
"@web3-onboard/core": "^2.14.0",
59+
"@web3-onboard/core": "^2.15.1-alpha.1",
5960
"@web3-onboard/dcent": "^2.2.3",
6061
"@web3-onboard/enkrypt": "^2.0.0",
6162
"@web3-onboard/fortmatic": "^2.0.14",
6263
"@web3-onboard/gas": "^2.1.4",
6364
"@web3-onboard/gnosis": "^2.1.6",
64-
"@web3-onboard/injected-wallets": "^2.6.2",
65+
"@web3-onboard/injected-wallets": "^2.8.0-alpha.1",
6566
"@web3-onboard/keepkey": "^2.3.3",
6667
"@web3-onboard/keystone": "^2.3.3",
6768
"@web3-onboard/ledger": "^2.4.2",
@@ -71,6 +72,7 @@
7172
"@web3-onboard/sequence": "^2.0.4",
7273
"@web3-onboard/tallyho": "^2.0.1",
7374
"@web3-onboard/torus": "^2.2.0",
75+
"@web3-onboard/transaction-preview": "^2.0.3-alpha.1",
7476
"@web3-onboard/trezor": "^2.3.3",
7577
"@web3-onboard/trust": "^2.0.0",
7678
"@web3-onboard/uauth": "^2.0.1",
-37.6 KB
Loading
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<script>
2+
import { onMount } from 'svelte'
3+
import { ethers } from 'ethers'
4+
5+
let transactionPreview
6+
let blocknativeSdk
7+
8+
const buildTransaction = async () => {
9+
const addressFrom = '0xab5801a7d398351b8be11c439e05c5b3259aec9b'
10+
11+
const CONTRACT_ADDRESS = '0x7a250d5630b4cf539739df2c5dacb4c659f2488d'
12+
const erc20_interface = [
13+
'function approve(address _spender, uint256 _value) public returns (bool success)',
14+
'function transferFrom(address sender, address recipient, uint256 amount) external returns (bool)',
15+
'function balanceOf(address owner) view returns (uint256)'
16+
]
17+
18+
const uniswapV2router_interface = [
19+
'function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)'
20+
]
21+
22+
const weth = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
23+
const uni = '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984'
24+
let swapTxData
25+
let approveTxData
26+
const createTransaction = async () => {
27+
const swapContract = new ethers.Contract(CONTRACT_ADDRESS, uniswapV2router_interface)
28+
const erc20_contract = new ethers.Contract(weth, erc20_interface)
29+
const oneHundredUni = ethers.BigNumber.from('100000000000000000000')
30+
approveTxData = await erc20_contract.populateTransaction.approve(
31+
CONTRACT_ADDRESS,
32+
oneHundredUni
33+
)
34+
35+
const amountOutMin = 0
36+
const amountOutMinHex = ethers.BigNumber.from(amountOutMin.toString())._hex
37+
38+
const path = [uni, weth]
39+
const deadline = Math.floor(Date.now() / 1000) + 60 * 1 // 1 minutes from the current Unix time
40+
41+
const inputAmountHex = oneHundredUni.toHexString()
42+
43+
swapTxData = await swapContract.populateTransaction.swapExactTokensForETH(
44+
inputAmountHex,
45+
amountOutMinHex,
46+
path,
47+
addressFrom,
48+
deadline
49+
)
50+
}
51+
await createTransaction()
52+
const account_address = '0xab5801a7d398351b8be11c439e05c5b3259aec9b'
53+
const uniswapV2Router = '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D'
54+
55+
return [
56+
{
57+
from: account_address,
58+
to: uni,
59+
input: approveTxData.data,
60+
gas: 1000000,
61+
gasPrice: 48000000000,
62+
value: 0
63+
},
64+
{
65+
from: account_address,
66+
to: uniswapV2Router,
67+
input: swapTxData.data,
68+
gas: 1000000,
69+
gasPrice: 48000000000,
70+
value: 0
71+
}
72+
]
73+
}
74+
75+
76+
const handlePreview = async () => {
77+
await transactionPreview.init({
78+
apiKey: '133a026b-c7a0-419c-a00b-66255b3cd487',
79+
sdk: blocknativeSdk,
80+
containerElement: '#tp-container'
81+
})
82+
83+
const stubTrans = await buildTransaction()
84+
await transactionPreview.previewTransaction(stubTrans)
85+
86+
}
87+
88+
onMount(async () => {
89+
const { default: Blocknative } = await import('bnc-sdk')
90+
const { default: transactionPreviewModule } = await import('@web3-onboard/transaction-preview')
91+
92+
blocknativeSdk = new Blocknative({
93+
dappId: '133a026b-c7a0-419c-a00b-66255b3cd487',
94+
networkId: 1
95+
})
96+
97+
transactionPreview = transactionPreviewModule({
98+
requireTransactionApproval: true
99+
})
100+
})
101+
</script>
102+
103+
<div>
104+
{#await blocknativeSdk && transactionPreview then Preview}
105+
{#if Preview}
106+
<button
107+
class="rounded-lg bg-gray-inverse hover:bg-gray-hover hover:text-gray-inverse transition-all px-4 h-10 text-base text-gray-current"
108+
on:click={() => handlePreview()}
109+
>
110+
Preview Transaction
111+
</button>
112+
113+
<div id="tp-container" />
114+
{/if}
115+
{/await}
116+
</div>
117+
118+
<style>
119+
#tp-container {
120+
height: auto;
121+
width: 316px;
122+
margin-top: 12px;
123+
}
124+
</style>

docs/src/lib/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './examples'
22
export * from './gas'
33
export { default as ThemeCustomizer } from './ThemeCustomizer.svelte'
4+
export { default as TransactionPreviewButton } from './TransactionPreviewButton.svelte'

docs/src/lib/services/onboard.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ const intiOnboard = async (theme) => {
181181
]
182182
},
183183
accountCenter: { desktop: { enabled: true }, mobile: { enabled: true } },
184-
theme: theme || 'system'
184+
theme: theme || 'system',
185+
apiKey: 'da1b962d-314d-4903-bfe1-426821d14a35'
185186
})
186187
}
187188

docs/src/routes/docs/[...3]modules/transaction-preview.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script>
22
import previewGif from '$lib/assets/transaction-preview.gif'
33
import previewImg from '$lib/assets/transaction-preview.png'
4+
import { TransactionPreviewButton } from '$lib/components'
45
</script>
56

67
# Transaction Preview
@@ -9,8 +10,12 @@ A modular UI for previewing a single or set of unsigned Ethereum transactions.
910

1011
<img src="{previewImg}" alt="Transaction Preview Flow image"/>
1112

12-
Full Simulation Platform API documentation can be found [here](https://docs.blocknative.com/transaction-preview-api)
13+
### Try Transaction Preview
14+
15+
Preview Vitalik swapping 100 UNI tokens for ETH using Transaction Preview
16+
<TransactionPreviewButton/>
1317

18+
Full Simulation Platform API documentation can be found [here](https://docs.blocknative.com/transaction-preview-api)
1419
### Install
1520

1621
<Tabs values={['yarn', 'npm']}>
@@ -74,13 +79,14 @@ const onboard = Onboard({
7479

7580
### Standalone Usage
7681

82+
To use the Transaction Preview package without web3-onboard all a developer needs to do is:
7783

78-
To use the Transaction Preview package without web3-onboard all a developer needs to do is:
7984
- Execute the entry function from the `@web3-onboard/transaction-preview` package and optional params
8085
- Run the returned `init` function with their [Blocknative API key](https://onboard.blocknative.com/docs/overview/introduction#optional-use-an-api-key-to-fetch-real-time-transaction-data-balances-gas), an initialized instance of their [Blocknative SDK](https://www.npmjs.com/package/bnc-sdk) and a containerElement string with the html ID of the target element to append the visualization to
8186
- Finally pass a transaction meant for a wallet provider (created using libraries like Ethers or Web3)
8287

8388
With the above steps a UI will be rendered with the balance changes and gas used.
89+
8490
```typescript
8591
import transactionPreviewModule from '@web3-onboard/transaction-preview'
8692

@@ -182,8 +188,7 @@ console.log(simData)
182188
```typescript
183189
export type TransactionPreviewModule = (options: TransactionPreviewOptions) => TransactionPreviewAPI
184190

185-
export type FullPreviewOptions = TransactionPreviewOptions &
186-
TransactionPreviewInitOptions
191+
export type FullPreviewOptions = TransactionPreviewOptions & TransactionPreviewInitOptions
187192

188193
export type TransactionPreviewAPI = {
189194
/**
@@ -209,9 +214,7 @@ export type TransactionPreviewAPI = {
209214
* Note: the package will need to initialized with the `init`
210215
* function prior to usage
211216
*/
212-
previewTransaction: (
213-
transaction: TransactionForSim[]
214-
) => Promise<MultiSimOutput>
217+
previewTransaction: (transaction: TransactionForSim[]) => Promise<MultiSimOutput>
215218
}
216219

217220
export type PatchedEIP1193Provider = EIP1193Provider & { simPatched: boolean }

docs/src/routes/docs/[...4]wallets/injected.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ const injected = injectedModule({
312312
- Rainbow - _Desktop & Mobile_
313313
- DeFiWallet - _Desktop & Mobile_
314314
- ApexWallet - _Desktop_
315+
- BifrostWallet - _Desktop & Mobile_
315316

316317
## Build Environments
317318

docs/yarn.lock

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2969,15 +2969,15 @@
29692969
ethers "5.5.4"
29702970
joi "^17.6.1"
29712971

2972-
"@web3-onboard/core@^2.14.0":
2973-
version "2.14.1"
2974-
resolved "https://registry.yarnpkg.com/@web3-onboard/core/-/core-2.14.1.tgz#20d5f8196cdd4455a6e2daa69319fb697733934c"
2975-
integrity sha512-d5rG4wg2gOUsgiNAaAucJOzDdIM2WTxLPBN/sXR1V6eWatn6YcXyduW7Nr0n1Hl/2d8eRnlHTeSeb9YA50niVw==
2972+
"@web3-onboard/core@^2.15.1-alpha.1":
2973+
version "2.15.1-alpha.1"
2974+
resolved "https://registry.yarnpkg.com/@web3-onboard/core/-/core-2.15.1-alpha.1.tgz#a6c241ba7eb84f40547e57b8192ecd46759ec5ad"
2975+
integrity sha512-CrAj0WkBxO52j2JUs5YFIbvfwyrUoWXO7B3QOG6VrQ9w4HRXO5lVBsD2RYMSA5fTbAbRZ7VwPiHCdmQ/ztKYLg==
29762976
dependencies:
29772977
"@unstoppabledomains/resolution" "^8.0"
29782978
"@web3-onboard/common" "^2.2.3"
29792979
bignumber.js "^9.0.0"
2980-
bnc-sdk "^4.6.5"
2980+
bnc-sdk "^4.6.7"
29812981
bowser "^2.11.0"
29822982
ethers "5.5.3"
29832983
eventemitter3 "^4.0.7"
@@ -3044,10 +3044,10 @@
30443044
joi "^17.6.1"
30453045
rxjs "^7.5.2"
30463046

3047-
"@web3-onboard/injected-wallets@^2.6.2":
3048-
version "2.6.2"
3049-
resolved "https://registry.yarnpkg.com/@web3-onboard/injected-wallets/-/injected-wallets-2.6.2.tgz#d6bebd623098c06868ad5c4efdaceb90082732e3"
3050-
integrity sha512-vOUWluIiYSrsC1TyFNFA0GXzcAFcfgy4mG6iXGJSjbNx9/54VilM6UtSaVhXb4diqQZyinuZj18UexdSxDAcfQ==
3047+
"@web3-onboard/injected-wallets@^2.8.0-alpha.1":
3048+
version "2.8.0-alpha.1"
3049+
resolved "https://registry.yarnpkg.com/@web3-onboard/injected-wallets/-/injected-wallets-2.8.0-alpha.1.tgz#eb3b8337c527348f1513bf14a25263a89446b95d"
3050+
integrity sha512-WjnoMv0kAeuJLRyhA0wqTVYwfRMmkir3igO1LxInbBADeHxbVVX+HcxO1zWpJaGkkDJOWvPSPHjlQJoNUZJFvg==
30513051
dependencies:
30523052
"@web3-onboard/common" "^2.2.3"
30533053
joi "^17.6.1"
@@ -3138,6 +3138,19 @@
31383138
"@toruslabs/torus-embed" "1.38.2"
31393139
"@web3-onboard/common" "^2.2.3"
31403140

3141+
"@web3-onboard/transaction-preview@^2.0.3-alpha.1":
3142+
version "2.0.3-alpha.1"
3143+
resolved "https://registry.yarnpkg.com/@web3-onboard/transaction-preview/-/transaction-preview-2.0.3-alpha.1.tgz#b8945c3b785dc1e0281709c01b464fe45aea1570"
3144+
integrity sha512-iJZtvGcYh3ZbmTzaNRAUWKmX4VwgbgaKbmlYCdmeOvNjB7fZykzqr9CXbGwwVmfI3xA7zT17hP5M0WjGFyuDFA==
3145+
dependencies:
3146+
"@web3-onboard/common" "^2.2.3"
3147+
bnc-sdk "^4.6.7"
3148+
bowser "^2.11.0"
3149+
joi "^17.6.1"
3150+
rxjs "^7.5.2"
3151+
svelte "^3.49.0"
3152+
svelte-i18n "^3.3.13"
3153+
31413154
"@web3-onboard/trezor@^2.3.3":
31423155
version "2.3.3"
31433156
resolved "https://registry.yarnpkg.com/@web3-onboard/trezor/-/trezor-2.3.3.tgz#0a9f2296e4e3365637a798eacfb3d2c0696e0b40"
@@ -3918,10 +3931,20 @@ bnb-javascript-sdk-nobroadcast@^2.16.14:
39183931
uuid "^3.3.2"
39193932
websocket-stream "^5.5.0"
39203933

3921-
bnc-sdk@^4.6.5:
3922-
version "4.6.5"
3923-
resolved "https://registry.yarnpkg.com/bnc-sdk/-/bnc-sdk-4.6.5.tgz#9f91eb2f213c0c4abf8b5f134f673a3f9a981ea2"
3924-
integrity sha512-W++M1kY5SensQUpig+EXqKEOfRgKrrobd8l3r9oOa06xJmxmMH4DPUm28IcESVX6NWj4I+bhgghOVDh/SFdE8Q==
3934+
bnc-sdk@^4.6.6:
3935+
version "4.6.6"
3936+
resolved "https://registry.yarnpkg.com/bnc-sdk/-/bnc-sdk-4.6.6.tgz#ef5501a0c68014efae24d00d2e3fb706318fa00d"
3937+
integrity sha512-cpavy/WBQrkw5PZpnuUAvxzj/RjmP1vSldOEG+nonf7n/4sykScDO6KrJN2oVhEMaxHOqOVf2rOugSL5t515eA==
3938+
dependencies:
3939+
crypto-es "^1.2.2"
3940+
nanoid "^3.3.1"
3941+
rxjs "^6.6.3"
3942+
sturdy-websocket "^0.1.12"
3943+
3944+
bnc-sdk@^4.6.7:
3945+
version "4.6.7"
3946+
resolved "https://registry.yarnpkg.com/bnc-sdk/-/bnc-sdk-4.6.7.tgz#138a22e04c95c2c697fb836092358d21957e2114"
3947+
integrity sha512-jIQ6cmeRBgvH/YDLuYRr2+kxDGcAAi0SOvjlO5nQ5cWdbslw+ASWftd1HmxiVLNCiwEH5bSc/t8a0agZ5njTUQ==
39253948
dependencies:
39263949
crypto-es "^1.2.2"
39273950
nanoid "^3.3.1"

0 commit comments

Comments
 (0)