diff --git a/src/lib/stellar/horizonQueries.js b/src/lib/stellar/horizonQueries.js index ddb1019..9f58ac8 100644 --- a/src/lib/stellar/horizonQueries.js +++ b/src/lib/stellar/horizonQueries.js @@ -1,7 +1,7 @@ import { error } from '@sveltejs/kit' -import { TransactionBuilder, Networks, StrKey, Asset, Horizon } from '@stellar/stellar-sdk'; +import { TransactionBuilder, Networks, StrKey, Asset, Horizon } from '@stellar/stellar-sdk' -const horizonUrl = 'https://horizon-testnet.stellar.org'; +const horizonUrl = 'https://horizon-testnet.stellar.org' const server = new Horizon.Server(horizonUrl) /** @@ -38,7 +38,16 @@ export async function fetchAccount(publicKey) { } catch (err) { // @ts-ignore if (err.response?.status === 404) { - throw error(404, 'account not funded on network') + try { + await fundWithFriendbot(publicKey) + + let account = await server.accounts().accountId(publicKey).call() + return account + } catch (err) { + throw error(500, { + message: `Unable to fund account ${publicKey}: ${err.message}`, + }) + } } else { // @ts-ignore throw error(err.response?.status ?? 400, {