joinCommunityOffChain method

Future<Map<String, dynamic>> joinCommunityOffChain(
  1. String walletAddress,
  2. String communityAddress, {
  3. String network = 'fuse',
  4. String? originNetwork = 'mainnet',
  5. String? tokenAddress,
  6. String? communityName,
})

Implementation

Future<Map<String, dynamic>> joinCommunityOffChain(
  String walletAddress,
  String communityAddress, {
  String network = 'fuse',
  String? originNetwork = 'mainnet',
  String? tokenAddress,
  String? communityName,
}) async {
  String nonce = await getNonceForRelay();
  print('nonce: $nonce');

  DeployedContract contract = await _contract(
    'CommunityManager',
    _communityManagerContractAddress,
  );
  Uint8List data = contract.function('joinCommunity').encodeCall([
    EthereumAddress.fromHex(walletAddress),
    EthereumAddress.fromHex(communityAddress)
  ]);
  String encodedData = '0x' + HEX.encode(data);
  print('encodedData: $encodedData');

  String signature = await signOffChain(
    _communityManagerContractAddress,
    walletAddress,
    BigInt.from(0),
    encodedData,
    nonce,
    BigInt.from(0),
    BigInt.from(_defaultGasLimit),
  );

  return {
    "walletAddress": walletAddress,
    "methodData": encodedData,
    "communityAddress": communityAddress,
    "nonce": nonce,
    "gasPrice": 0,
    "network": network,
    "gasLimit": _defaultGasLimit,
    "signature": signature,
    "walletModule": "CommunityManager",
    "methodName": "joinCommunity",
    "transactionBody": {
      "tokenAddress": tokenAddress,
      "originNetwork": originNetwork,
      "status": 'pending',
      "communityName": communityName,
    }
  };
}