Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): Add warning when wallet balance is below build cost #1467

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/cli/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ export async function build({
const chainName = chainInfo?.name || 'unknown chain';
const nativeCurrencySymbol = chainInfo?.nativeCurrency.symbol || 'ETH';
let totalCost = BigInt(0);

let balance = BigInt(0);

const runtimeOptions = {
provider,
chainId,
Expand All @@ -124,6 +125,8 @@ export async function build({
async function (addr: viem.Address) {
const client = provider as unknown as viem.TestClient;

balance = await provider.getBalance({address: addr});

// on test network any user can be conjured
await client.impersonateAccount({ address: addr });
await client.setBalance({ address: addr, value: viem.parseEther('10000') });
Expand Down Expand Up @@ -482,7 +485,6 @@ export async function build({
)
)
);
log(gray(`Total Cost: ${viem.formatEther(totalCost)} ${nativeCurrencySymbol}`));
log('');
log(
'- Rerunning the build command will attempt to execute skipped operations. It will not rerun executed operations. (To rerun executed operations, delete the partial build package generated by this run by adding the --wipe flag to the build command on the next run.)'
Expand All @@ -500,6 +502,9 @@ export async function build({
if (!persist) {
log(bold(`💥 ${fullPackageRef} would be successfully built on ${chainName} (Chain ID: ${chainId})`));
log(gray(`Estimated Total Cost: ${viem.formatEther(totalCost)} ${nativeCurrencySymbol}`));
if (totalCost > balance) {
log(yellow(`Your wallet does not have enough ${nativeCurrencySymbol} to complete this build`));
}
log();

log(
Expand All @@ -519,6 +524,7 @@ export async function build({
} else {
log(bold(`💥 ${fullPackageRef} built on ${chainName} (Chain ID: ${chainId})`));
log(gray(`Total Cost: ${viem.formatEther(totalCost)} ${nativeCurrencySymbol}`));
log();
}
log();

Expand Down
Loading