How to use CrossChainEnabled

I noticed CrossChainEnabled was introduced into the new contracts version 4.6.0.

I've been experimenting with Polygon's official token bridge and NFT bridge, so am very interested to see how we can use OpenZeppelin's new CrossChainEnabled contract (instead?). It appears this is using an alternative to Polygon's official bridges called Fx-Portal which Polygon also supports, based on their documentation at https://docs.polygon.technology/docs/develop/l1-l2-communication/fx-portal .

So to enable compatibility of a token with Polygon's FX-Portal bridge would the token contract code be like this?:

contract TokenTest is ERC1155, CrossChainEnabledPolygonChild {
    constructor(
        address bridge
        // ...
        )
    ERC1155("URI")
    CrossChainEnabledPolygonChild(bridge)
    // ...
    {
        // ....
    }
// ...
}

How about to enable compatibility with other bridges too? Can we simply add after is: CrossChainEnabledAMB, CrossChainEnabledArbitrumL1, CrossChainEnabledArbitrumL2, CrossChainEnabledOptimism, CrossChainEnabledPolygonChild?

Currently, a contract can only be made compatible with a single bridge at a time. If you want to deploy to multiple networks, what you have to do is create an abstract contract and the specialize it separately for each network, like this:

abstract contract TokenTest is ERC1155, CrossChainEnabled {
   ...
}

contract TokenTestPolygon is TokenTest, CrossChainEnabledPolygonChild {
}

contract TokenTestAMB is TokenTest, CrossChainEnabledAMB {
}

And so on.

Our contracts for Polygon use FxPortal, which is a generalized message passing bridge, whereas the other bridges you mention are specialized to bridge tokens and NFTs.

1 Like

Thank you @frangio for the abstract contract code suggestion.

How about for the token contract on the Ethereum network, does any code need to be included to make it work with the bridges?

The ideal goal would be to enable tokens to be migratable across various networks and via various bridges.

Fx-Portal can be used for transferring tokens. Do you mean that the OpenZeppelin code for Polygon is limited to only passing messages from Ethereum to Polygon?

Are the contracts for AMB, Arbitrum, Optimism to enable token transfer across their bridges?

The CrossChainEnabled abstraction is about receiving arbitrary message. We do not currently have any mechanism to bridge tokens out of the box. This could be built on top of CrossChainEnabled, but it requires some additional work.

Axelar seems to be the solution to what I was looking for, as it enables cross-chain asset transfer, and I think the asset contract itself doesn't require additional code for it to be migratable across chains.