Skip to content

Commit

Permalink
deploy: 250250c
Browse files Browse the repository at this point in the history
  • Loading branch information
hal3e committed Mar 14, 2024
1 parent f3c8825 commit 66bfff2
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 44 deletions.
27 changes: 15 additions & 12 deletions master/calling-contracts/cost-estimation.html
Original file line number Diff line number Diff line change
Expand Up @@ -138,24 +138,23 @@ <h1 class="menu-title">The Fuel Rust SDK</h1>
<div id="content" class="content">
<main>
<h1 id="estimating-contract-call-cost"><a class="header" href="#estimating-contract-call-cost">Estimating contract call cost</a></h1>
<p>With the function <code>estimate_transaction_cost(tolerance: Option&lt;f64&gt;)</code> provided by <code>ContractCallHandler</code> and <code>ContractMultiCallHandler</code>, you can get a cost estimation for a specific call. The return type, <code>TransactionCost</code>, is a struct that contains relevant information for the estimation:</p>
<pre><code class="language-rust ignore">TransactionCost {
min_gas_price: u64,
min_byte_price: u64,
gas_price: u64,
gas_used: u64,
metered_bytes_size: u64,
total_fee: f64, // where total_fee is the sum of the gas and byte fees
<p>With the function <code>estimate_transaction_cost(tolerance: Option&lt;f64&gt;, block_horizon: Option&lt;u32&gt;)</code> provided by <code>ContractCallHandler</code> and <code>ContractMultiCallHandler</code>, you can get a cost estimation for a specific call. The return type, <code>TransactionCost</code>, is a struct that contains relevant information for the estimation:</p>
<pre><code class="language-rust ignore">pub struct TransactionCost {
pub gas_price: u64,
pub gas_used: u64,
pub metered_bytes_size: u64,
pub total_fee: u64,
}
</code></pre>
<p>Below are examples that show how to get the estimated transaction cost from single and multi call transactions.</p>
<pre><code class="language-rust ignore"> let contract_instance = MyContract::new(contract_id, wallet);

let tolerance = 0.0;
let tolerance = Some(0.0);
let block_horizon = Some(1);
let transaction_cost = contract_instance
.methods()
.initialize_counter(42) // Build the ABI call
.estimate_transaction_cost(Some(tolerance)) // Get estimated transaction cost
.estimate_transaction_cost(tolerance, block_horizon) // Get estimated transaction cost
.await?;
</code></pre>
<pre><code class="language-rust ignore"> let mut multi_call_handler = MultiContractCallHandler::new(wallet.clone());
Expand All @@ -167,12 +166,16 @@ <h1 id="estimating-contract-call-cost"><a class="header" href="#estimating-contr
.add_call(call_handler_1)
.add_call(call_handler_2);

let tolerance = 0.0;
let tolerance = Some(0.0);
let block_horizon = Some(1);
let transaction_cost = multi_call_handler
.estimate_transaction_cost(Some(tolerance)) // Get estimated transaction cost
.estimate_transaction_cost(tolerance, block_horizon) // Get estimated transaction cost
.await?;
</code></pre>
<p>The transaction cost estimation can be used to set the gas limit for an actual call, or to show the user the estimated cost.</p>
<blockquote>
<p><strong>Note</strong> The same estimation interface is available for scripts.</p>
</blockquote>

</main>

Expand Down
8 changes: 4 additions & 4 deletions master/calling-contracts/tx-policies.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ <h1 id="transaction-policies"><a class="header" href="#transaction-policies">Tra
<!-- tx_policies:example:start -->
<p>Transaction policies are defined as follows:</p>
<pre><code class="language-rust ignore">pub struct TxPolicies {
gas_price: Option&lt;u64&gt;,
tip: Option&lt;u64&gt;,
witness_limit: Option&lt;u64&gt;,
maturity: Option&lt;u64&gt;,
max_fee: Option&lt;u64&gt;,
Expand All @@ -151,20 +151,20 @@ <h1 id="transaction-policies"><a class="header" href="#transaction-policies">Tra
</code></pre>
<p>Where:</p>
<ol>
<li><strong>Gas Price</strong> - Maximum gas price for transaction.</li>
<li><strong>Tip</strong> - amount to pay the block producer to prioritize the transaction.</li>
<li><strong>Witness Limit</strong> - The maximum amount of witness data allowed for the transaction.</li>
<li><strong>Maturity</strong> - Block until which the transaction cannot be included.</li>
<li><strong>Max Fee</strong> - The maximum fee payable by this transaction.</li>
<li><strong>Script Gas Limit</strong> - The maximum amount of gas the transaction may consume for executing its script code.</li>
</ol>
<p>When the <strong>Script Gas Limit</strong> is not set, the Rust SDK will estimate the consumed gas in the background and set it as the limit. Similarly, if no <strong>Gas Price</strong> is defined, the Rust SDK defaults to the network's minimum gas price.</p>
<p>When the <strong>Script Gas Limit</strong> is not set, the Rust SDK will estimate the consumed gas in the background and set it as the limit.</p>
<p>If the <strong>Witness Limit</strong> is not set, the SDK will set it to the size of all witnesses and signatures defined in the transaction builder.</p>
<p>You can configure these parameters by creating an instance of <code>TxPolicies</code> and passing it to a chain method called <code>with_tx_policies</code>:</p>
<!-- tx_policies:example:end-->
<pre><code class="language-rust ignore"> let contract_methods = MyContract::new(contract_id.clone(), wallet.clone()).methods();

let tx_policies = TxPolicies::default()
.with_gas_price(1)
.with_tip(1)
.with_script_gas_limit(1_000_000)
.with_maturity(0);

Expand Down
2 changes: 1 addition & 1 deletion master/custom-transactions/transaction-builders.html
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ <h2 id="creating-a-custom-transaction"><a class="header" href="#creating-a-custo
<p><strong>Note</strong> It is recommended to add signers before calling <code>adjust_for_fee()</code> as the estimation will include the size of the witnesses.</p>
</blockquote>
<p>We can also define transaction policies. For example, we can limit the gas price by doing the following:</p>
<pre><code class="language-rust ignore"> let tx_policies = TxPolicies::default().with_gas_price(1);
<pre><code class="language-rust ignore"> let tx_policies = TxPolicies::default().with_tip(1);
let tb = tb.with_tx_policies(tx_policies);
</code></pre>
<p>Our builder needs a signature from the hot wallet to unlock its coins before we call <code>build()</code> and submit the resulting transaction through the provider:</p>
Expand Down
2 changes: 1 addition & 1 deletion master/deploying/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ <h2 id="deploying-a-contract-binary"><a class="header" href="#deploying-a-contra

// Optional: Configure deployment parameters
let tx_policies = TxPolicies::default()
.with_gas_price(0)
.with_tip(1)
.with_script_gas_limit(1_000_000)
.with_maturity(0);

Expand Down
43 changes: 22 additions & 21 deletions master/print.html
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,7 @@ <h2 id="deploying-a-contract-binary"><a class="header" href="#deploying-a-contra

// Optional: Configure deployment parameters
let tx_policies = TxPolicies::default()
.with_gas_price(0)
.with_tip(1)
.with_script_gas_limit(1_000_000)
.with_maturity(0);

Expand Down Expand Up @@ -1630,7 +1630,7 @@ <h2 id="deploying-a-contract-binary"><a class="header" href="#deploying-a-contra
<!-- tx_policies:example:start -->
<p>Transaction policies are defined as follows:</p>
<pre><code class="language-rust ignore">pub struct TxPolicies {
gas_price: Option&lt;u64&gt;,
tip: Option&lt;u64&gt;,
witness_limit: Option&lt;u64&gt;,
maturity: Option&lt;u64&gt;,
max_fee: Option&lt;u64&gt;,
Expand All @@ -1639,20 +1639,20 @@ <h2 id="deploying-a-contract-binary"><a class="header" href="#deploying-a-contra
</code></pre>
<p>Where:</p>
<ol>
<li><strong>Gas Price</strong> - Maximum gas price for transaction.</li>
<li><strong>Tip</strong> - amount to pay the block producer to prioritize the transaction.</li>
<li><strong>Witness Limit</strong> - The maximum amount of witness data allowed for the transaction.</li>
<li><strong>Maturity</strong> - Block until which the transaction cannot be included.</li>
<li><strong>Max Fee</strong> - The maximum fee payable by this transaction.</li>
<li><strong>Script Gas Limit</strong> - The maximum amount of gas the transaction may consume for executing its script code.</li>
</ol>
<p>When the <strong>Script Gas Limit</strong> is not set, the Rust SDK will estimate the consumed gas in the background and set it as the limit. Similarly, if no <strong>Gas Price</strong> is defined, the Rust SDK defaults to the network's minimum gas price.</p>
<p>When the <strong>Script Gas Limit</strong> is not set, the Rust SDK will estimate the consumed gas in the background and set it as the limit.</p>
<p>If the <strong>Witness Limit</strong> is not set, the SDK will set it to the size of all witnesses and signatures defined in the transaction builder.</p>
<p>You can configure these parameters by creating an instance of <code>TxPolicies</code> and passing it to a chain method called <code>with_tx_policies</code>:</p>
<!-- tx_policies:example:end-->
<pre><code class="language-rust ignore"> let contract_methods = MyContract::new(contract_id.clone(), wallet.clone()).methods();

let tx_policies = TxPolicies::default()
.with_gas_price(1)
.with_tip(1)
.with_script_gas_limit(1_000_000)
.with_maturity(0);

Expand Down Expand Up @@ -1996,24 +1996,23 @@ <h2 id="output-values"><a class="header" href="#output-values">Output values</a>
<p><strong>Note:</strong> <code>estimate_tx_dependencies()</code> can also be used when working with script calls or multi calls. <code>estimate_tx_dependencies()</code> does not currently resolve the dependencies needed for logging from an external contract. For more information, see <a href="calling-contracts/./logs.html">here</a>. If no resolution was found after exhausting all simulation attempts, the last received error will be propagated. The same will happen if an error is unrelated to transaction dependencies.</p>
</blockquote>
<div style="break-before: page; page-break-before: always;"></div><h1 id="estimating-contract-call-cost"><a class="header" href="#estimating-contract-call-cost">Estimating contract call cost</a></h1>
<p>With the function <code>estimate_transaction_cost(tolerance: Option&lt;f64&gt;)</code> provided by <code>ContractCallHandler</code> and <code>ContractMultiCallHandler</code>, you can get a cost estimation for a specific call. The return type, <code>TransactionCost</code>, is a struct that contains relevant information for the estimation:</p>
<pre><code class="language-rust ignore">TransactionCost {
min_gas_price: u64,
min_byte_price: u64,
gas_price: u64,
gas_used: u64,
metered_bytes_size: u64,
total_fee: f64, // where total_fee is the sum of the gas and byte fees
<p>With the function <code>estimate_transaction_cost(tolerance: Option&lt;f64&gt;, block_horizon: Option&lt;u32&gt;)</code> provided by <code>ContractCallHandler</code> and <code>ContractMultiCallHandler</code>, you can get a cost estimation for a specific call. The return type, <code>TransactionCost</code>, is a struct that contains relevant information for the estimation:</p>
<pre><code class="language-rust ignore">pub struct TransactionCost {
pub gas_price: u64,
pub gas_used: u64,
pub metered_bytes_size: u64,
pub total_fee: u64,
}
</code></pre>
<p>Below are examples that show how to get the estimated transaction cost from single and multi call transactions.</p>
<pre><code class="language-rust ignore"> let contract_instance = MyContract::new(contract_id, wallet);

let tolerance = 0.0;
let tolerance = Some(0.0);
let block_horizon = Some(1);
let transaction_cost = contract_instance
.methods()
.initialize_counter(42) // Build the ABI call
.estimate_transaction_cost(Some(tolerance)) // Get estimated transaction cost
.estimate_transaction_cost(tolerance, block_horizon) // Get estimated transaction cost
.await?;
</code></pre>
<pre><code class="language-rust ignore"> let mut multi_call_handler = MultiContractCallHandler::new(wallet.clone());
Expand All @@ -2025,12 +2024,16 @@ <h2 id="output-values"><a class="header" href="#output-values">Output values</a>
.add_call(call_handler_1)
.add_call(call_handler_2);

let tolerance = 0.0;
let tolerance = Some(0.0);
let block_horizon = Some(1);
let transaction_cost = multi_call_handler
.estimate_transaction_cost(Some(tolerance)) // Get estimated transaction cost
.estimate_transaction_cost(tolerance, block_horizon) // Get estimated transaction cost
.await?;
</code></pre>
<p>The transaction cost estimation can be used to set the gas limit for an actual call, or to show the user the estimated cost.</p>
<blockquote>
<p><strong>Note</strong> The same estimation interface is available for scripts.</p>
</blockquote>
<div style="break-before: page; page-break-before: always;"></div><h1 id="low-level-calls"><a class="header" href="#low-level-calls">Low-level calls</a></h1>
<!-- This section should explain what low-level calls are and how to do them -->
<p>With low-level calls, you can specify the parameters of your calls at runtime and make indirect calls through other contracts.</p>
Expand Down Expand Up @@ -2123,9 +2126,7 @@ <h2 id="output-values"><a class="header" href="#output-values">Output values</a>
</code></pre>
<h2 id="running-scripts-with-transaction-policies"><a class="header" href="#running-scripts-with-transaction-policies">Running scripts with transaction policies</a></h2>
<p>The method for passing transaction policies is the same as <a href="./calling-contracts/tx-policies.html">with contracts</a>. As a reminder, the workflow would look like this:</p>
<pre><code class="language-rust ignore"> let tx_policies = TxPolicies::default()
.with_gas_price(1)
.with_script_gas_limit(1_000_000);
<pre><code class="language-rust ignore"> let tx_policies = TxPolicies::default().with_script_gas_limit(1_000_000);
let result = script_instance
.main(a, b)
.with_tx_policies(tx_policies)
Expand Down Expand Up @@ -2538,7 +2539,7 @@ <h2 id="creating-a-custom-transaction"><a class="header" href="#creating-a-custo
<p><strong>Note</strong> It is recommended to add signers before calling <code>adjust_for_fee()</code> as the estimation will include the size of the witnesses.</p>
</blockquote>
<p>We can also define transaction policies. For example, we can limit the gas price by doing the following:</p>
<pre><code class="language-rust ignore"> let tx_policies = TxPolicies::default().with_gas_price(1);
<pre><code class="language-rust ignore"> let tx_policies = TxPolicies::default().with_tip(1);
let tb = tb.with_tx_policies(tx_policies);
</code></pre>
<p>Our builder needs a signature from the hot wallet to unlock its coins before we call <code>build()</code> and submit the resulting transaction through the provider:</p>
Expand Down
4 changes: 1 addition & 3 deletions master/running-scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ <h1 id="running-scripts"><a class="header" href="#running-scripts">Running scrip
</code></pre>
<h2 id="running-scripts-with-transaction-policies"><a class="header" href="#running-scripts-with-transaction-policies">Running scripts with transaction policies</a></h2>
<p>The method for passing transaction policies is the same as <a href="./calling-contracts/tx-policies.html">with contracts</a>. As a reminder, the workflow would look like this:</p>
<pre><code class="language-rust ignore"> let tx_policies = TxPolicies::default()
.with_gas_price(1)
.with_script_gas_limit(1_000_000);
<pre><code class="language-rust ignore"> let tx_policies = TxPolicies::default().with_script_gas_limit(1_000_000);
let result = script_instance
.main(a, b)
.with_tx_policies(tx_policies)
Expand Down
2 changes: 1 addition & 1 deletion master/searchindex.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion master/searchindex.json

Large diffs are not rendered by default.

0 comments on commit 66bfff2

Please sign in to comment.