npm install @upcoming/multichain-widget
Import the component and accompanying styles:
import '@rainbow-me/rainbowkit/styles.css'
import { MultichainWidget } from '@upcoming/multichain-widget'
import '@upcoming/multichain-widget/styles.css'Then simply place the component in your app:
<MultichainWidget />It is possible to specify query params or pass some props to <MultichainWidget /> to customize its behavior:
Colors, fonts, sizes, etc. can be overwritten by using this prop.
Does not support query params.
Callbacks can be specified for various events in the flow. The most important hook is the onCompletion hook, which is called when the flow is completed successfully.
Applications embedding the widget and conditionally rendering it can use this hook to unmount the widget when the flow is done.
Does not support query params.
Mainly used to customize the gnosisJsonRpcProviders array.
Does not support query params.
The intent modifies the information text displayed on the first screen. Possible values are initial-funding, postage-batch and arbitrary.
Can be specified in the query params with the intent key.
The default target address where the xBZZ and xDAI tokens will be sent.
Can be specified in the query params with the destination key.
The default amount of xDAI to receive at the end of the flow.
Can be specified in the query params with the dai key.
The default amount of xBZZ to receive at the end of the flow.
Can be specified in the query params with the bzz key.
- Cross-swap a token to xDAI using Relay, goes to a temporary wallet.
- Swap xDAI to xBZZ using SushiSwap, goes to the user's wallet.
- Transfer any remaining xDAI to the user's wallet.
We use the Relay API to cross-swap to xDAI.
We use SushiSwap contracts and its API to swap xDAI to xBZZ.
data-test-id="intent"data-test-id="target-address-input"data-test-id="xdai-input"data-test-id="xbzz-input"data-test-id="continue"data-test-id="export-keys"
data-test-id="error-invalid-address"data-test-id="error-bad-address-checksum"data-test-id="error-not-enough-bzz"
data-test-id="go-back"data-test-id="readonly-source-address"data-test-id="readonly-target-address"data-test-id="source-chain-input"data-test-id="source-chain-input__1"the number represents the network id, in this case 1 for Ethereum Mainnetdata-test-id="source-token-input"data-test-id="source-token-input__0xdac17f958d2ee523a2206206994597c13d831ec7"the address represents the token, in this case USDTdata-test-id="swap-summary"(e.g. "You will swap 0.0814 (~$0.081) USDT from Ethereum to fund:")data-test-id="xdai-display__left"(e.g. "0.01 xDAI")data-test-id="xdai-display__right"(e.g. "$0.01")data-test-id="xbzz-display__left"(e.g. "0.500 xBZZ")data-test-id="xbzz-display__right"(e.g. "$0.06")data-test-id="quote-status"data-test-id="quote-status__description"(e.g. "Quote available")data-test-id="fund"
data-test-id="quote-status__completed"data-test-id="quote-status__pending"data-test-id="quote-status__failed"
data-test-id="go-back"disableddata-test-id="readonly-source-address"data-test-id="readonly-target-address"data-test-id="status-step-1"- ...
data-test-id="status-step-6"data-test-id="fund"disabled
data-test-id="status-step-1__pending"data-test-id="status-step-1__skipped"data-test-id="status-step-1__completed"data-test-id="status-step-1__in-progress"data-test-id="status-step-1__failed"- ...
data-test-id="status-step-6__pending"data-test-id="status-step-6__skipped"data-test-id="status-step-6__completed"data-test-id="status-step-6__in-progress"data-test-id="status-step-6__failed"
Most styles can be overwritten by passing a theme prop to the MultichainWidget component.
A backup of every generated private key is stored in localStorage with a timestamp suffix to avoid collisions.
Hooks can be set by passing hooks prop to the MultichainWidget component. Currently supported hooks are:
beforeTransactionStartonFatalErroronCompletiononUserAbort
- Pass the
mode=batchquery param to the widget to switch to batch creation mode. - Pass
destination=0x${string}to specify the desired owner of the postage batch. This is NOT related to the payer address. - Recommended to pass
intent=postage-batchto adjust the information text on the first screen. - Optionally pass the
reserved-slots=2query param to specify the number of intended reserved slots per bucket within the batch. This adjusts the capacity displayed on the first page and shifts the underlying depth values.
Example:
https://fund.ethswarm.org/?mode=batch&destination=0x45a1502382541Cd610CC9068e88727426b696293&intent=postage-batch&reserved-slots=2
Messages are posted to the window that hosts the widget: window.parent when the widget is embedded in an iframe, or window.opener when it is opened as a popup with window.open (there window.parent is the popup itself). Hosts should verify event.source and event.origin before trusting a message.
{ event: 'error', error }{ event: 'finish' }{ event: 'batch', batchId: 0x${string}, depth: number, amount: numberString, blockNumber: 0x${string} }{ event: 'payment', phase: 'sent' | 'delivered', chainId: number, resumed: boolean, txHash?: 0x${string}, temporaryAddress?: 0x${string} }
Example:
{
"event": "batch",
"batchId": "0xfe48d3cd7ec9cdf455811894d63683b1fac8b358501b843892b372e355155b62",
"depth": 21,
"amount": "10453363201",
"blockNumber": "0x2a828b8"
}The payment event tells the host that money is in flight, so it can avoid closing the
widget after the point of no return, and can find the funds later if the flow is interrupted.
phase: 'sent'— the payment transaction succeeded (txHashis onchainId, the source chain). Point of no return: the funds will be delivered totemporaryAddresswhether or not the widget is still open.phase: 'delivered'— the xDAI arrived ontemporaryAddress; the remaining steps run on Gnosis (chainIdis 100, notxHash).resumed: true— the temporary wallet was already funded, so the deposit was skipped and no new payment was made. Emitted withphase: 'delivered'; the funds are just as much in flight as after a fresh payment.temporaryAddressis present whenever the payment routes through the temporary wallet, which is where funds can get stranded if the widget is interrupted. It is absent when Relay delivers to the destination address directly (fundingmode from a non-Gnosis chain): that path has no temporary wallet and no further steps, so it emitssentonly — its completion is thefinishevent.
Example:
{
"event": "payment",
"phase": "delivered",
"chainId": 100,
"temporaryAddress": "0x45a1502382541Cd610CC9068e88727426b696293",
"resumed": false
}Adding the mocked=true query param to the widget URL will make the widget use mocked data and skip actual transactions. This is useful for testing and development purposes.