|
| 1 | +--- |
| 2 | +id: sygma-props |
| 3 | +slug: /sygma-widget/props |
| 4 | +title: Properties |
| 5 | +description: The following section provides details on utilizing widget properties |
| 6 | +sidebar_position: 5 |
| 7 | +--- |
| 8 | + |
| 9 | +# Widget Properties |
| 10 | + |
| 11 | +The behaviour of the Sygma Widget can be customized using configurable properties (props). A complete reference of the properties can be found under [packages/widget/src/widget.ts](https://github.com/sygmaprotocol/sygma-widget/blob/main/packages/widget/src/widget.ts). |
| 12 | + |
| 13 | +:::info |
| 14 | +Note that some properties require installing additional dependencies. |
| 15 | +::: |
| 16 | + |
| 17 | +The currently available properties are: |
| 18 | +- **environment** |
| 19 | + - Desc: Determines whether the widget operates on the live network (mainnet) or a testing environment (testnet). |
| 20 | + - Usage: |
| 21 | + 1. Install `@polkadot/types` dependency: `yarn add -D @polkadot/types` |
| 22 | + 2. Configure either MAINNET or TESTNET environment inside the SygmaProtocolReactWidget: `<SygmaProtocolReactWidget environment={Environment.MAINNET} />` |
| 23 | +- **whitelistedSourceNetworks** |
| 24 | + - Desc: Specifies which blockchain networks can be selected as the source for transactions. |
| 25 | + - Usage: `<SygmaProtocolReactWidget whitelistedSourceNetworks={["sepolia"]} />` |
| 26 | +- **whitelistedDestinationNetworks** |
| 27 | + - Desc: Specifies which blockchain networks can be selected as the destination for transactions. |
| 28 | + - Usage: `<SygmaProtocolReactWidget whitelistedDestinationNetworks={["cronos"]} />` |
| 29 | +- **whitelistedSourceResources** |
| 30 | + - Desc: Defines which assets or resources (e.g., tokens) can be selected for transaction. |
| 31 | + - Usage: `<SygmaProtocolReactWidget whitelistedSourceResources={["resourceID1", "resourceID2"]} />` |
| 32 | +- **substrateProviders** |
| 33 | + - Desc: Specifies the API endpoints or connection details for Substrate-based blockchain networks. |
| 34 | + - Usage: |
| 35 | + 1. Install `@polkadot-daily-snapshots/api` dependency: `yarn add -D @polkadot-daily-snapshots/api` |
| 36 | + 2. Add import statements to the top of the app: |
| 37 | + `import { ApiPromise, WsProvider } from '@polkadot/api';` |
| 38 | + 3. Setup a setState action: |
| 39 | + ```ts |
| 40 | + const [substrateProviders, setSubstrateProviders] = useState<ApiPromise[]>( |
| 41 | + [] |
| 42 | + ); |
| 43 | + ``` |
| 44 | + 4. Initialize the provider: |
| 45 | + ```ts |
| 46 | + useEffect(() => { |
| 47 | + const provider = new WsProvider('wss://rhala-node.phala.network/ws'); |
| 48 | + const api = new ApiPromise({ provider }); |
| 49 | + api.isReady.then(() => { |
| 50 | + console.log('API is ready'); |
| 51 | + setSubstrateProviders([api]); |
| 52 | + }); |
| 53 | + }, []); |
| 54 | + ``` |
| 55 | + 5. Pass into the component: |
| 56 | + ```ts |
| 57 | + <SygmaProtocolReactWidget |
| 58 | + substrateProviders={substrateProviders} |
| 59 | + /> |
| 60 | + ``` |
| 61 | + |
| 62 | + |
| 63 | +## Using Props In An Example |
| 64 | + |
| 65 | +Below you will find an example of props being passed to whitelist (i.e enable) the source and destination networks in the React component: |
| 66 | + |
| 67 | +```ts |
| 68 | +// App.tsx |
| 69 | +import React from "react"; |
| 70 | +import { SygmaProtocolReactWidget } from "@buildwithsygma/sygmaprotocol-react-widget"; |
| 71 | +import { Environment } from '@buildwithsygma/sygma-sdk-core'; |
| 72 | +
|
| 73 | +function MyDapp() { |
| 74 | + const [count, setCount] = useState(0); |
| 75 | +
|
| 76 | + return ( |
| 77 | + <SygmaProtocolReactWidget |
| 78 | + whitelistedSourceNetworks={["sepolia"]} |
| 79 | + whitelistedDestinationNetworks={["cronos"]} |
| 80 | + /> |
| 81 | + ); |
| 82 | +} |
| 83 | +``` |
0 commit comments