injectEthereumScript static method

String injectEthereumScript(
  1. WalletWeb3Provider wallet
)

Support only Ethereum network Script to add config for network and address Add web view handler to listen

Implementation

static String injectEthereumScript(WalletWeb3Provider wallet) {
  String source = """
    (function() {
        var config = {
            ethereum: {
                address: "${wallet.address}",
                chainId: ${wallet.chainId},
                rpcUrl: "${wallet.rpcUrl ?? ''}",
                isDebug: true,
            },
        };

        trustwallet.ethereum = new trustwallet.Provider(config);

        trustwallet.postMessage = (json) => {
            window.flutter_inappwebview.callHandler("_tw_", json);
        };

        window.ethereum = trustwallet.ethereum;
    })();
  """;
  return source;
}