Skip to content

Commit

Permalink
Merge pull request #2 from candidelabs/feat/add-check-for-supported-g…
Browse files Browse the repository at this point in the history
…as-tokens-example

add check for supported gas tokens in example
  • Loading branch information
sherifahmed990 authored Sep 18, 2023
2 parents bc83dcd + 27ad02b commit 9298bbd
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,22 @@ async function main(): Promise<void> {
entrypointAddress,
paymasterRPC
)
let paymasterAndDataResult = await paymaster.getPaymasterCallDataForPayingGasWithErc20(user_operation, erc20TokenAddress)
const supportedGasTokens = await paymaster.getSupportedERC20Tokens();

if ("code" in supportedGasTokens) {
const errorresult = supportedGasTokens as JsonRpcError
const errorMessage = errorresult.message
console.log(errorMessage);
return
}

const gasToken = supportedGasTokens.tokens.find(token => token.address === erc20TokenAddress.toLowerCase());
if (!gasToken) {
console.log("Gas token selected is not supported");
return
}

let paymasterAndDataResult = await paymaster.getPaymasterCallDataForPayingGasWithErc20(user_operation, gasToken.address)
console.log(paymasterAndDataResult)
if("code" in paymasterAndDataResult){
const errorresult = paymasterAndDataResult as JsonRpcError
Expand Down

0 comments on commit 9298bbd

Please sign in to comment.