Skip to content

Commit

Permalink
feat: Use infura for polygon
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Apr 25, 2024
1 parent f05066a commit dd14aec
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/app/shared/constants/parameters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Parameters {
static const web3RpcMainnetUrl = 'https://mainnet.infura.io/v3/';

static const POLYGON_MAIN_NETWORK = 'main';
static const INFURA_URL = 'https://polygon-mainnet.infura.io/v3/';
static const POLYGON_INFURA_URL = 'https://polygon-mainnet.infura.io/v3/';
static const INFURA_RDP_URL = 'wss://polygon-mainnet.infura.io/v3/';
static const ID_STATE_CONTRACT_ADDR =
'0x624ce98D2d27b20b8f8d521723Df8fC4db71D79D';
Expand Down
13 changes: 10 additions & 3 deletions lib/app/shared/helper_functions/helper_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2117,15 +2117,22 @@ String? getWalletAddress(CredentialSubjectModel credentialSubjectModel) {
Future<String> fetchRpcUrl(BlockchainNetwork blockchainNetwork) async {
String rpcUrl = '';

if (blockchainNetwork is PolygonNetwork ||
blockchainNetwork is BinanceNetwork ||
if (blockchainNetwork is BinanceNetwork ||
blockchainNetwork is FantomNetwork) {
rpcUrl = blockchainNetwork.rpcNodeUrl as String;
} else {
if (blockchainNetwork.networkname == 'Mainnet') {
await dotenv.load();
final String infuraApiKey = dotenv.get('INFURA_API_KEY');
const String prefixUrl = Parameters.web3RpcMainnetUrl;

late String prefixUrl;

if (blockchainNetwork is PolygonNetwork) {
prefixUrl = Parameters.POLYGON_INFURA_URL;
} else {
prefixUrl = Parameters.web3RpcMainnetUrl;
}

return '$prefixUrl$infuraApiKey';
} else {
rpcUrl = blockchainNetwork.rpcNodeUrl as String;
Expand Down
4 changes: 2 additions & 2 deletions lib/polygon_id/cubit/polygon_id_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class PolygonIdCubit extends Cubit<PolygonIdState> {
currentNetwork = PolygonIdNetwork.PolygonMainnet;
await polygonId.init(
network: network,
web3Url: Parameters.INFURA_URL,
web3Url: Parameters.POLYGON_INFURA_URL,
web3RdpUrl: Parameters.INFURA_RDP_URL,
web3ApiKey: dotenv.get('INFURA_API_KEY'),
idStateContract: Parameters.ID_STATE_CONTRACT_ADDR,
Expand Down Expand Up @@ -147,7 +147,7 @@ class PolygonIdCubit extends Cubit<PolygonIdState> {
network = Parameters.POLYGON_MAIN_NETWORK;
await polygonId.setEnv(
network: Parameters.POLYGON_MAIN_NETWORK,
web3Url: Parameters.INFURA_URL,
web3Url: Parameters.POLYGON_INFURA_URL,
web3RdpUrl: Parameters.INFURA_RDP_URL,
web3ApiKey: dotenv.get('INFURA_API_KEY'),
idStateContract: Parameters.ID_STATE_CONTRACT_ADDR,
Expand Down

0 comments on commit dd14aec

Please sign in to comment.