Skip to content

Commit

Permalink
add try catch
Browse files Browse the repository at this point in the history
  • Loading branch information
pivilartisant committed Dec 2, 2024
1 parent 0dea26a commit ae26d5b
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions src/bearbyWallet/BearbyAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,30 +247,35 @@ export class BearbyAccount implements Provider {
}

public async deploySC(params: DeploySCParams): Promise<SmartContract> {
const fee = Number(params.fee ?? (await this.minimalFee()));
const totalCost =
StorageCost.smartContract(params.byteCode.length) + params.coins;

const args = {
...params,
maxCoins: totalCost,
maxGas: params.maxGas || MAX_GAS_DEPLOYMENT,
coins: params.coins,
fee: fee,
gasPrice: 10000n, // dummy value waiting for (https://github.com/bearby-wallet/bearby-web3/pull/25)
contractDataBase64: uint8ArrayToBase64(params.byteCode),
deployerBase64: uint8ArrayToBase64(DEPLOYER_BYTECODE),
};
try {
const fee = Number(params.fee ?? (await this.minimalFee()));
const totalCost =
StorageCost.smartContract(params.byteCode.length) + params.coins;

const args = {
...params,
maxCoins: totalCost,
maxGas: params.maxGas || MAX_GAS_DEPLOYMENT,
coins: params.coins,
fee: fee,
gasPrice: 10000n, // dummy value waiting for (https://github.com/bearby-wallet/bearby-web3/pull/25)
contractDataBase64: uint8ArrayToBase64(params.byteCode),
deployerBase64: uint8ArrayToBase64(DEPLOYER_BYTECODE),
};

const operationId = await web3.contract.deploy(args);
const operationId = await web3.contract.deploy(args);

const operation = new Operation(this, operationId);
const operation = new Operation(this, operationId);

const deployedAddress = await operation.getDeployedAddress(
params.waitFinalExecution,
);
const deployedAddress = await operation.getDeployedAddress(
params.waitFinalExecution,
);

return new SmartContract(this, deployedAddress);
return new SmartContract(this, deployedAddress);
} catch (error) {
console.error('Error deploying smart contract:', error);

Check warning on line 276 in src/bearbyWallet/BearbyAccount.ts

View workflow job for this annotation

GitHub Actions / format

Unexpected console statement

Check warning on line 276 in src/bearbyWallet/BearbyAccount.ts

View workflow job for this annotation

GitHub Actions / format / format

Unexpected console statement
throw new Error(`Failed to deploy smart contract: ${error.message}`);
}
}

public async getOperationStatus(opId: string): Promise<OperationStatus> {
Expand Down

0 comments on commit ae26d5b

Please sign in to comment.