Widget Properties
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.
info
Note that some properties require installing additional dependencies.
The currently available properties are:
- environment
- Desc: Determines whether the widget operates on the live network (mainnet) or a testing environment (testnet).
- Usage:
- Install
@polkadot/types
dependency:yarn add -D @polkadot/types
- Configure either MAINNET or TESTNET environment inside the SygmaProtocolReactWidget:
<SygmaProtocolReactWidget environment={Environment.MAINNET} />
- Install
- whitelistedSourceNetworks
- Desc: Specifies which blockchain networks can be selected as the source for transactions.
- Usage:
<SygmaProtocolReactWidget whitelistedSourceNetworks={["sepolia"]} />
- whitelistedDestinationNetworks
- Desc: Specifies which blockchain networks can be selected as the destination for transactions.
- Usage:
<SygmaProtocolReactWidget whitelistedDestinationNetworks={["cronos"]} />
- whitelistedSourceResources
- Desc: Defines which assets or resources (e.g., tokens) can be selected for transaction.
- Usage:
<SygmaProtocolReactWidget whitelistedSourceResources={["resourceID1", "resourceID2"]} />
- substrateProviders
- Desc: Specifies the API endpoints or connection details for Substrate-based blockchain networks.
- Usage:
- Install
@polkadot/api
dependency:yarn add @polkadot/api
- Add import statements to the top of the app:
import { ApiPromise, WsProvider } from '@polkadot/api';
- Setup a
setState
action:const [substrateProviders, setSubstrateProviders] = useState<ApiPromise[]>([]);
- Initialize the Substrate provider:
useEffect(() => {
const provider = new WsProvider('[YOUR_SUBSTRATE_WSS_PROVIDER_HERE]');
const api = new ApiPromise({ provider });
api.isReady.then(() => {
console.log('API is ready');
setSubstrateProviders([api]);
});
}, []); - Pass the provider into the component:
<SygmaProtocolReactWidget
substrateProviders={substrateProviders}
/>
- Install
Using Props In An Example
Below you will find an example of props being passed to whitelist (i.e enable) the source and destination networks in the React component:
// App.tsx
import React from "react";
import { SygmaProtocolReactWidget } from "@buildwithsygma/sygmaprotocol-react-widget";
import { Environment } from '@buildwithsygma/sygma-sdk-core';
function MyDapp() {
const [count, setCount] = useState(0);
return (
<SygmaProtocolReactWidget
whitelistedSourceNetworks={["sepolia"]}
whitelistedDestinationNetworks={["cronos"]}
/>
);
}