From 7fb85cea457937b0812791e0c15d69ea0d6ba05e Mon Sep 17 00:00:00 2001 From: Atatakai Date: Tue, 1 Oct 2024 18:36:50 +0400 Subject: [PATCH] (registry) fix: add gas estimation to creating agent and component --- .../components/ListAgents/mint.jsx | 18 ++++++++++-------- .../components/ListComponents/mint.jsx | 18 ++++++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/apps/autonolas-registry/components/ListAgents/mint.jsx b/apps/autonolas-registry/components/ListAgents/mint.jsx index 35e7e8ae..dbd0f5b7 100644 --- a/apps/autonolas-registry/components/ListAgents/mint.jsx +++ b/apps/autonolas-registry/components/ListAgents/mint.jsx @@ -3,6 +3,8 @@ import { useRouter } from 'next/router'; import { Typography } from 'antd'; import { notifyError, notifySuccess } from '@autonolas/frontend-library'; +import { getEstimatedGasLimit } from 'libs/util-functions/src'; + import RegisterForm from 'common-util/List/RegisterForm'; import { AlertSuccess, AlertError } from 'common-util/List/ListCommon'; import { getMechMinterContract } from 'common-util/Contracts'; @@ -41,14 +43,14 @@ const MintAgent = () => { const contract = getMechMinterContract(account); - const fn = contract.methods - .create( - '1', - values.owner_address, - `0x${values.hash}`, - values.dependencies ? values.dependencies.split(', ') : [], - ) - .send({ from: account }); + const createFn = contract.methods.create( + '1', + values.owner_address, + `0x${values.hash}`, + values.dependencies ? values.dependencies.split(', ') : [], + ); + const estimatedGas = await getEstimatedGasLimit(createFn, account); + const fn = createFn.send({ from: account, gasLimit: estimatedGas }); sendTransaction(fn, account) .then((result) => { diff --git a/apps/autonolas-registry/components/ListComponents/mint.jsx b/apps/autonolas-registry/components/ListComponents/mint.jsx index 4b9fa4af..f1dc464d 100644 --- a/apps/autonolas-registry/components/ListComponents/mint.jsx +++ b/apps/autonolas-registry/components/ListComponents/mint.jsx @@ -3,6 +3,8 @@ import { useRouter } from 'next/router'; import { Typography } from 'antd'; import { notifyError, notifySuccess } from '@autonolas/frontend-library'; +import { getEstimatedGasLimit } from 'libs/util-functions/src'; + import RegisterForm from 'common-util/List/RegisterForm'; import { AlertSuccess, AlertError } from 'common-util/List/ListCommon'; import { getMechMinterContract } from 'common-util/Contracts'; @@ -40,14 +42,14 @@ const MintComponent = () => { } const contract = getMechMinterContract(); - const fn = contract.methods - .create( - '0', - values.owner_address, - `0x${values.hash}`, - values.dependencies ? values.dependencies.split(', ') : [], - ) - .send({ from: account }); + const createFn = contract.methods.create( + '0', + values.owner_address, + `0x${values.hash}`, + values.dependencies ? values.dependencies.split(', ') : [], + ); + const estimatedGas = await getEstimatedGasLimit(createFn, account); + const fn = createFn.send({ from: account, gasLimit: estimatedGas }); sendTransaction(fn, account) .then((result) => {