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 gas estimation and fix option deploy argument #604

Merged
merged 3 commits into from
May 16, 2024
Merged
Changes from 1 commit
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
17 changes: 14 additions & 3 deletions packages/massa-web3/src/experimental/smartContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ export class SmartContract {
* @param client - The client to connect to the desired blockchain.
* @param account - The account that will deploy the smart contract.
* @param contract - The contract to deploy.
* @param opts - Optional deployment details.
* @param opts - Optional deployment details. Default to
* - fee: auto-estimated fee,
* - maxCoins: auto-estimated cost,
* - maxGas: auto-estimated gas,
* - periodToLive: 10,
* - waitFinalExecution: true.
*
*
* @returns The deployed smart contract.
*
Expand All @@ -98,7 +104,9 @@ export class SmartContract {
account: Account,
// TODO: Handle multiple contracts
contract: DeployContract,
opts: DeployOptions
opts: DeployOptions = {
waitFinalExecution: true,
}
): Promise<SmartContract> {
const totalCost =
StorageCost.smartContract(contract.byteCode.length) + contract.coins
Expand Down Expand Up @@ -254,6 +262,8 @@ export class SmartContract {
/**
* Returns the gas estimation for a given function.
*
* @remarks To avoid running out of gas, the gas estimation is increased by 20%.
*
* @param func - The function to estimate the gas cost.
* @param parameter - The parameter for the function call in Uint8Array format.
* @param callerAddress - The address of the caller.
Expand All @@ -278,6 +288,7 @@ export class SmartContract {
throw new Error(result.info.error)
}

return BigInt(result.info.gasCost)
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
return (BigInt(result.info.gasCost) * 120n) / 100n
}
}
Loading