Skip to content

Commit 562e71e

Browse files
committed
fix: fixed StarknetID integration and contratcs interactions
1 parent 23e2503 commit 562e71e

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
"devDependencies": {
3434
"@types/bun": "latest",
3535
"@types/cors": "^2.8.17",
36-
"@types/express": "^5.0.0",
37-
"@types/node": "^20.17.24",
36+
"@types/express": "^5.0.1",
37+
"@types/node": "^20.17.25",
3838
"conventional-changelog-cli": "^5.0.0"
3939
},
4040
"peerDependencies": {
@@ -45,7 +45,7 @@
4545
"cors": "^2.8.5",
4646
"express": "^4.21.2",
4747
"starknet": "^6.23.1",
48-
"starknetid.js": "3.0.2",
48+
"starknetid.js": "4.0.3",
4949
"zod": "^3.24.2"
5050
},
5151
"keywords": [

src/core/services/balance.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async function getTokenBalance(
4444
const formattedOwnerAddress = parseStarknetAddress(ownerAddress);
4545

4646
// Create contract instance
47-
const contract = getContract(formattedTokenAddress, provider, network);
47+
const contract = await getContract(formattedTokenAddress, provider, network);
4848

4949
try {
5050
// Get balance and decimals in parallel
@@ -160,7 +160,7 @@ export async function getERC20Balance(
160160
try {
161161
// Get token symbol
162162
const provider = getProvider(network);
163-
const contract = getContract(parseStarknetAddress(tokenAddress), provider, network);
163+
const contract = await getContract(parseStarknetAddress(tokenAddress), provider, network);
164164
const symbolResponse = await contract.call('symbol', []);
165165

166166
// Parse symbol
@@ -212,7 +212,7 @@ export async function isNFTOwner(
212212
const formattedOwnerAddress = parseStarknetAddress(ownerAddress);
213213

214214
// Create NFT contract
215-
const contract = getContract(formattedTokenAddress, provider, network);
215+
const contract = await getContract(formattedTokenAddress, provider, network);
216216

217217
// Convert tokenId to bigint if it's a string
218218
const tokenIdBigInt = typeof tokenId === 'string' ? BigInt(tokenId) : tokenId;
@@ -253,7 +253,7 @@ export async function getERC721Balance(
253253
const formattedOwnerAddress = parseStarknetAddress(ownerAddress);
254254

255255
// Create NFT contract
256-
const contract = getContract(formattedTokenAddress, provider, network);
256+
const contract = await getContract(formattedTokenAddress, provider, network);
257257

258258
// Call balanceOf directly
259259
const response = await contract.call('balanceOf', [formattedOwnerAddress]);

src/core/services/clients.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,20 @@ export function getAccount(
7575
* @param network Network name
7676
* @returns Contract instance
7777
*/
78-
export function getContract(
78+
export async function getContract(
7979
contractAddress: string,
8080
provider?: ProviderInterface,
8181
network = 'mainnet'
82-
): Contract {
82+
): Promise<Contract> {
8383
const contractProvider = provider || getProvider(network);
8484
const formattedAddress = parseStarknetAddress(contractAddress);
8585

86+
// Fetch the contract class using getClassAt to get the ABI
87+
const contractClass = await contractProvider.getClassAt(formattedAddress);
88+
const abi = contractClass.abi || [];
89+
8690
return new Contract(
87-
[], // No ABI needed initially - can be set later using contract.attachABI()
91+
abi,
8892
formattedAddress,
8993
contractProvider
9094
);

src/core/services/tokens.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export async function getTokenInfo(
3535
}> {
3636
const provider = getProvider(network);
3737
const formattedAddress = parseStarknetAddress(tokenAddress);
38-
const contract = getContract(formattedAddress, provider, network);
38+
const contract = await getContract(formattedAddress, provider, network);
3939

4040
// Call contract to get token information using parallel requests
4141
const [nameResponse, symbolResponse, decimalsResponse] = await Promise.all([
@@ -111,7 +111,7 @@ export async function getTokenTotalSupply(
111111
}> {
112112
const formattedAddress = parseStarknetAddress(tokenAddress);
113113
const provider = getProvider(network);
114-
const contract = getContract(formattedAddress, provider, network);
114+
const contract = await getContract(formattedAddress, provider, network);
115115

116116
// Get token decimals and supply in parallel
117117
const [decimalsResponse, supplyResponse] = await Promise.all([

src/core/services/transfer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ export async function transferERC20(
215215
let decimals = params.decimals;
216216
if (decimals === undefined) {
217217
const provider = getProvider(network);
218-
const contract = getContract(tokenAddress, provider, network);
218+
const contract = await getContract(tokenAddress, provider, network);
219219
const decimalsResponse = await contract.call('decimals', []);
220220
decimals = Number(decimalsResponse.toString());
221221
}

0 commit comments

Comments
 (0)