estimateGasAndCollateral
Virtually executes a transaction, returns an estimate for the size of storage collateralized and the gas used by the transaction. The transaction will not be added to the blockchain.
Usage
example.ts
import { account, publicClient } from "./config";
const estimate = await publicClient.estimateGasAndCollateral({
account,
data: "0x",
to: "cfx:...",
});
Returns
The estimate.
Parameters
account
- Type:
Account | Address
The Account to call from.
Accepts Local Account (Private Key, etc).
export const account = privateKeyToAccount("0x...", { networkId: mainnet.id });
const estimate = await publicClient.estimateGasAndCollateral({
account: account,
data: "0x",
to: "cfx:...",
});
const estimate = await publicClient.estimateGasAndCollateral({
account: "cfx:...",
data: "0x",
to: "cfx:...",
});
to
- Type:
Address
The contract address or recipient.
const estimate = await publicClient.estimateGasAndCollateral({
account: "cfx:...",
data: "0x",
to: "cfx:...",
});
gasPrice (optional)
- Type:
bigint
The price (in drip) to pay per gas. Only applies to Legacy Transactions.
import { parseGDrip } from "cive";
const estimate = await publicClient.estimateGasAndCollateral({
account: "cfx:...",
data: "0x",
to: "cfx:...",
gasPrice: parseGDrip("20"),
});
gas (optional)
- Type:
bigint
The gas provided for transaction execution.
const estimate = await publicClient.estimateGasAndCollateral({
account: "cfx:...",
data: "0x",
to: "cfx:...",
gas: 1_000_000n,
});
value (optional)
- Type:
bigint
Value (in drip) sent with this transaction.
import { parseCFX } from "cive";
const estimate = await publicClient.estimateGasAndCollateral({
account: "cfx:...",
data: "0x",
to: "cfx:...",
value: parseCFX("1"),
});
nonce (optional)
- Type:
bigint
Unique number identifying this transaction.
const estimate = await publicClient.estimateGasAndCollateral({
account: "cfx:...",
nonce: 1,
to: "cfx:...",
});
accessList (optional)
- Type:
AccessList
The access list.
const estimate = await publicClient.estimateGasAndCollateral({
account: "cfx:...",
to: "cfx:...",
accessList: [
{
address: "cfx:...",
storageKeys: ["0x1"],
},
],
});
maxFeePerGas (optional)
- Type:
bigint
Total fee per gas (in drip), inclusive of maxPriorityFeePerGas
.
import { parseGDrip } from "cive";
const estimate = await publicClient.estimateGasAndCollateral({
account: "cfx:...",
to: "cfx:...",
maxFeePerGas: parseGDrip("20"),
});
maxPriorityFeePerGas (optional)
- Type:
bigint
Max priority fee per gas (in drip).
import { parseGDrip } from "cive";
const estimate = await publicClient.estimateGasAndCollateral({
account: "cfx:...",
to: "cfx:...",
maxFeePerGas: parseGDrip("20"),
maxPriorityFeePerGas: parseGDrip("2"),
});