Skip to content

Commit 1cb4ce6

Browse files
authored
Merge pull request #657 from LIT-Protocol/feature/lit-3904-js-sdk-fix-custom-rpc-url-is-not-respected
fix: `rpcUrl` should be used when provided in the `getStakingContract` function
2 parents 41a854b + d900f09 commit 1cb4ce6

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

packages/contracts-sdk/src/lib/contracts-sdk.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,18 +606,33 @@ export class LitContracts {
606606
this.connected = true;
607607
};
608608

609+
/**
610+
* Retrieves the Staking contract instance based on the provided network, context, and RPC URL.
611+
* If a context is provided, it determines if a contract resolver is used for bootstrapping contracts.
612+
* If a resolver address is present in the context, it retrieves the Staking contract from the contract resolver instance.
613+
* Otherwise, it retrieves the Staking contract using the contract address and ABI from the contract context.
614+
* Throws an error if required contract data is missing or if the Staking contract cannot be obtained.
615+
*
616+
* @param network - The network key.
617+
* @param context - The contract context or contract resolver context.
618+
* @param rpcUrl - The RPC URL.
619+
* @returns The Staking contract instance.
620+
* @throws Error if required contract data is missing or if the Staking contract cannot be obtained.
621+
*/
609622
public static async getStakingContract(
610623
network: LIT_NETWORKS_KEYS,
611624
context?: LitContractContext | LitContractResolverContext,
612625
rpcUrl?: string
613626
) {
614627
let provider: ethers.providers.StaticJsonRpcProvider;
615-
rpcUrl = RPC_URL_BY_NETWORK[network];
628+
629+
const _rpcUrl = rpcUrl || RPC_URL_BY_NETWORK[network];
630+
616631
if (context && 'provider' in context!) {
617632
provider = context.provider;
618633
} else {
619634
provider = new ethers.providers.StaticJsonRpcProvider({
620-
url: rpcUrl,
635+
url: _rpcUrl,
621636
skipFetchSetup: true,
622637
});
623638
}

0 commit comments

Comments
 (0)