Skip to content

Commit

Permalink
fixing ERC-20 contract read using WAGMI 👛
Browse files Browse the repository at this point in the history
  • Loading branch information
dysbulic committed Jul 15, 2024
1 parent 11d9c91 commit 4163b66
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { polygon } from 'viem/chains';
const { amountToDecimal } = numbers;

/**
* As a first iteration, we only allow people to create quests if they hold more that 100 pSEED tokens
* As a first iteration, we only allow people to
* create quests if they hold more that 100 pSEED tokens
*/

export async function isAllowedToCreateQuest(
Expand All @@ -20,12 +21,12 @@ export async function isAllowedToCreateQuest(
Constants.PSEED_ADDRESS,
polygonClient,
);
const pSEEDBalance = await pSEEDContract.balanceOf(playerAddress);
const pSEEDDecimals = await pSEEDContract.decimals();
const pSEEDBalance = await pSEEDContract.read.balanceOf([playerAddress]);
const pSEEDDecimals = await pSEEDContract.read.decimals();
const minimumPooledSeedBalance = BigInt(Constants.PSEED_FOR_QUEST);
const pSEEDBalanceInDecimal = amountToDecimal(
pSEEDBalance.toString(),
pSEEDDecimals,
pSEEDBalance as string,
pSEEDDecimals as number,
);

const allowed = BigInt(pSEEDBalanceInDecimal) >= minimumPooledSeedBalance;
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/lib/abis/ERC20.json
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,4 @@
"name": "Transfer",
"type": "event"
}
]
]
2 changes: 1 addition & 1 deletion packages/backend/src/lib/ethereum.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ERC20_ABI from './abis/ERC20.json' assert { type: 'json' };
import { getContract, PublicClient } from 'viem';

export const getERC20Contract = async (
export const getERC20Contract = (
contractAddress: `0x${string}`,
client: PublicClient
) => (
Expand Down

0 comments on commit 4163b66

Please sign in to comment.