Update Account Thresholds
The "Update Thresholds" component allows users to update their Stellar accounts low, medium and high operation thresholds.
Features
- Updates a Stellar accounts low, medium and high operation thresholds for performing transactions, adding authorization and more.
- Displays a success message when the thresholds are updated successfully.
Usage
- Click on the "Update Thresholds" button.
- Enter the new low, medium and high thresholds.
- Click on the "Update Thresholds" button to update the thresholds.
- A success message will be displayed if the thresholds are updated successfully.
- The updated thresholds will be displayed in the "Current Thresholds" section.
Additional Resources
Each task is categorized into one of three thresholds: low, medium, or high, each assigned a numeric level between 0 and 255. This level dictates the required signature weight for authorizing the task. For further details, refer to Stellars documentation section on Operations and Transactions.
Review the documentation on thresholds below, you can permanently lock yourself out of the account
C#
Install the Pakana.Stellar.Components NuGet package via the NuGet Package Manager Console.
.Net8.0 or greater is required.
dotnet add package Pakana.Stellar.Components
StellarSDK Dependency will install automatically
<pakana.stellar.components.Pages.ChangeThreshold/>
@page "/Threshold"
@inject IJSRuntime JSRuntime
@rendermode InteractiveAuto
<h2>Update Thresholds</h2>
<label for="accountInput">Account Public Key:</label>
<InputText id="accountInput" @bind-Value="accountPublicKey" placeholder="Enter account public key" />
<br>
<br>
<label for="lowThresholdInput">Low Threshold:</label>
<InputNumber id="lowThresholdInput" @bind-Value="lowThreshold" min="0" max="255" placeholder="Enter low threshold" />
<br>
<br>
<label for="medThresholdInput">Medium Threshold:</label>
<InputNumber id="medThresholdInput" @bind-Value="medThreshold" min="0" max="255" placeholder="Enter medium threshold" />
<br>
<br>
<label for="highThresholdInput">High Threshold:</label>
<InputNumber id="highThresholdInput" @bind-Value="highThreshold" min="0" max="255" placeholder="Enter high threshold" />
<br>
<br>
<label for="secretKeyInput">Account Secret Key:</label>
<InputText id="secretKeyInput" @bind-Value="secretKey" type="password" placeholder="Enter account secret key" />
<br>
<br>
<button @onclick="UpdateThresholds">Update Thresholds</button>
<p>@resultMessageon</p>
@code {
private string accountPublicKey;
private int lowThreshold;
private int medThreshold;
private int highThreshold;
private string secretKey;
private string resultMessageon;
private async Task UpdateThresholds()
{
try
{
await JSRuntime.InvokeVoidAsync("interop.updateThresholds", accountPublicKey, lowThreshold, medThreshold, highThreshold, secretKey);
resultMessageon = "Thresholds updated successfully!";
}
catch (Exception ex)
{
resultMessageon = "Error updating thresholds. Please try again.";
Console.WriteLine(ex.Message);
}
}
protected override void OnAfterRender(bool firstRender)
{
if (firstRender)
{
LoadStellarSDK();
}
}
private void LoadStellarSDK()
{
JSRuntime.InvokeVoidAsync("eval", JSContent());
}
private string JSContent() => @"
window.interop = {
updateThresholds: async function (accountPublicKey, lowThreshold, medThreshold, highThreshold, secretKey) {
try {
const server = new StellarSdk.Horizon.Server('https://horizon-testnet.stellar.org');
const account = await server.loadAccount(accountPublicKey);
const transaction = new StellarSdk.TransactionBuilder(account, {
fee: StellarSdk.BASE_FEE,
networkPassphrase: StellarSdk.Networks.TESTNET,
})
.addOperation(StellarSdk.Operation.setOptions({
lowThreshold: lowThreshold,
medThreshold: medThreshold,
highThreshold: highThreshold
}))
.setTimeout(180)
.build();
transaction.sign(StellarSdk.Keypair.fromSecret(secretKey));
const response = await server.submitTransaction(transaction);
console.log('Transaction response:', response);
} catch (error) {
console.error('Error updating thresholds:', error);
throw new Error('Error updating thresholds: ' + error.message);
}
}
};
import('https://cdnjs.cloudflare.com/ajax/libs/stellar-sdk/11.3.0/stellar-sdk.min.js').then(() => {
console.log('Stellar SDK loaded.');
}).catch(error => console.error('Failed to load Stellar SDK:', error));
";
}
Javascript
We've provided simple HTML and JavaScript that can be used in your project as partial-components or be customized and integrated into your existing codebase.
*Current Version as of 2024-24-02*
<script src="https://cdnjs.cloudflare.com/ajax/libs/stellar-sdk/11.2.2/stellar-sdk.js"></script>
<script>
async function updateThresholds() {
try {
const accountPublicKey = document.getElementById('accountInput').value.trim();
const lowThreshold = parseInt(document.getElementById('lowThresholdInput').value, 10);
const medThreshold = parseInt(document.getElementById('medThresholdInput').value, 10);
const highThreshold = parseInt(document.getElementById('highThresholdInput').value, 10);
const secretKey = document.getElementById('secretKeyInput').value.trim();
const server = new StellarSdk.Horizon.Server('https://horizon-testnet.stellar.org');
const account = await server.loadAccount(accountPublicKey);
const transaction = new StellarSdk.TransactionBuilder(account, {
fee: StellarSdk.BASE_FEE,
networkPassphrase: StellarSdk.Networks.TESTNET,
})
.addOperation(StellarSdk.Operation.setOptions({
lowThreshold: lowThreshold,
medThreshold: medThreshold,
highThreshold: highThreshold
}))
.setTimeout(180)
.build();
// Sign the transaction with the account's secret key
transaction.sign(StellarSdk.Keypair.fromSecret(secretKey));
// Submit the transaction to the Stellar network
const response = await server.submitTransaction(transaction);
console.log('Transaction response:', response);
document.getElementById('resultMessage').textContent = 'Thresholds updated successfully!';
} catch (error) {
console.error('Error updating thresholds:', error);
// Check if error object and response property exist
if (error && error.response && error.response.data) {
console.error('Detailed error response:', error.response.data.extras.result_codes);
}
document.getElementById('resultMessage').textContent = 'Error updating thresholds. Please try again.';
}
}
</script>
<body>
<h1>Update Thresholds</h1>
<label for="accountInput">Account Public Key:</label>
<input type="text" id="accountInput" placeholder="Enter account public key">
<br>
<br>
<label for="lowThresholdInput">Low Threshold:</label>
<input type="number" id="lowThresholdInput" min="0" max="255" placeholder="Enter low threshold">
<br>
<br>
<label for="medThresholdInput">Medium Threshold:</label>
<input type="number" id="medThresholdInput" min="0" max="255" placeholder="Enter medium threshold">
<br>
<br>
<label for="highThresholdInput">High Threshold:</label>
<input type="number" id="highThresholdInput" min="0" max="255" placeholder="Enter high threshold">
<br>
<br>
<label for="secretKeyInput">Account Secret Key:</label>
<input type="password" id="secretKeyInput" placeholder="Enter account secret key">
<br>
<br>
<button onclick="updateThresholds()">Update Thresholds</button>
<p id="resultMessage"></p>
</body>