diff --git a/packages/cli/src/deploy/ensureContract.ts b/packages/cli/src/deploy/ensureContract.ts index eaebbcf69d..959c9b663b 100644 --- a/packages/cli/src/deploy/ensureContract.ts +++ b/packages/cli/src/deploy/ensureContract.ts @@ -4,6 +4,8 @@ import { deployer } from "./ensureDeployer"; import { salt } from "./common"; import { sendTransaction } from "@latticexyz/common"; import { debug } from "./debug"; +import pRetry from "p-retry"; +import { wait } from "@latticexyz/common/utils"; export async function ensureContract({ client, @@ -24,10 +26,21 @@ export async function ensureContract({ debug("deploying", label, "at", address); return [ - await sendTransaction(client, { - chain: client.chain ?? null, - to: deployer, - data: concatHex([salt, bytecode]), - }), + await pRetry( + () => + sendTransaction(client, { + chain: client.chain ?? null, + to: deployer, + data: concatHex([salt, bytecode]), + }), + { + retries: 3, + onFailedAttempt: async (error) => { + const delay = error.attemptNumber * 500; + debug(`failed to deploy ${label}, retrying in ${delay}ms...`); + await wait(delay); + }, + } + ), ]; }