How to set up Crosschain Streaming using Superfluid with Etherspot
Etherspot have teamed up with Superfluid to allow Crosschain Streaming. This allows you to stream assets to another Etherspot-supported blockchain.
Before we continue, please ensure that you have had a look at our Supported Ethereum Chains, followed the steps in Install Etherspot SDK and how to Bootstrap Etherspot SDK. We're assuming that you have completed these steps before going forward.
Before we continue...
We're going to need a few things ready to go. For this example. we're going to use two testnets:
Goerli (Ethereum testnet)
Mumbai (Polygon tesnet)
... and we're going be using two tokens:
ETH on Goerli: 0x0000000000000000000000000000000000000000
ERC-20 Test Token on Mumbai: 0xA6FA4fB5f76172d178d61B04b0ecd319C5d1C0aa
Let's set this up in our code.
import { Sdk as EtherspotSdk, NetworkNames, randomPrivateKey,} from'etherspot';// ...// First, define the tokensconstfromToken='0x0000000000000000000000000000000000000000';consttoToken='0xA6FA4fB5f76172d178d61B04b0ecd319C5d1C0aa';// Next, instantiate our SDKs for each networkconstetherspotGoerliSdk=newEtherspotSdk({ privateKey:randomPrivateKey(),}, { networkName:NetworkNames.Goerli,});constetherspotMumbaiSdk=newEtherspotSdk({ privateKey:randomPrivateKey(),}, { networkName:NetworkNames.Mumbai,});// Finally, compute the contract account addresses ahead of time// The responses will return the account details.constgoerliAccount=awaitetherspotGoerliSdk.computeContractAccount();constmumbaiAccount=awaitetherspotMumbaiSdk.computeContractAccount();
Now we have two Etherspot accounts ready to go.
Supported Chains
Not all chains are supported. We have created an SDK method that allows you to fetch the supported chains. This helps minimise wasted time testing what chains might be supported.
import { CrossChainServiceProvider } from'etherspot';// Keep this for future use.constsupporteChains=awaitsdk.getCrossChainBridgeSupportedChains({ serviceProvider:this.serviceProvider});
Be sure to check whatever chains you are working with against the list returned above!
Supported Tokens
As with the Supported Chains above, we also provide a helper SDK method to return the supported list of tokens between two chains. This can save you alot of time and effort.
We're now going to create a Superfluid Token Wrapper.
import { ethers } from'ethers';import { SuperTokenFactoryContract, SuperTokenContract,} from'etherspot';// Build the transaction to create the Superfluid// ERC20 Super TokenconstcreateSuperERC20Tx=await etherspotMumbaiSdk.createSuperERC20WrapperTransactionPayload( toToken );// Add this to the Etherspot transaction batchawaitetherspotMumbaiSdk.batchExecuteAccountTransaction(createSuperERC20Tx);consttxResponse=awaitthis.toWallet.sendTransaction(awaitetherspotMumbaiSdk.encodeGatewayBatch());consttxReceipt=awaittxResponse.wait();constfactoryContract=newSuperTokenFactoryContract();constfactoryCreated= factoryContract.parseLogs(txReceipt.logs).find(log => log &&log.event ==='SuperTokenCreated');constsuperTokenAddress=factoryCreated.args[0];awaitsdk.clearGatewayBatch();constsuperTokenContract=newSuperTokenContract(this.superTokenAddress);
Perform necessary transactions
In order to continue, we need to ensure that we can perform the necessary actions. The below code will ensure these are met.