Components
Addsigner

Add Signer

The "Add Signer" component allows the Owner(s) to add a new signer to the newly created wallet and set a weight for the new signer.

Features

  • Collects source address, new signers public address, and the desired weight for the new signer.

Additional Resources

Signatures serve as authorization for transactions within the network. Every transaction must be authorized by at least one public key to be considered valid, and typically, this authorization comes from the source account's signature. In certain cases, transactions may require multiple signatures, a concept we'll explore further in the section covering multisignature (multisig) setups.

⚠️

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

NuGet Package Implementation
<pakana.stellar.components.Pages.AddSigner/>
C#
@page "/AddSigner"
@rendermode InteractiveAuto
 
<h2>Add Signer to Stellar Account</h2>
<div>
    <input type="text" id="accountSecret" placeholder="Enter account secret
key">
    <input type="text" id="signerPublicKey" placeholder="Enter signer public
key">
    <input type="text" id="signerWeight" placeholder="Enter signer weight">
    <button onclick="addSigner()">Add Signer</button>
</div>
@code{
    string secretKey {set;get;} = "";
    string signerPublicKey {set;get;} = "";
    int signerWeight {set;get;} = 1;
 
}
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/stellar-sdk/11.2.2/stellar-sdk.min.js"></script>
<script src="../js/addSigner.js"></script>
C# - JS File
function addSigner() {
    const accountSecret = document.getElementById("accountSecret").value;
    const signerPublicKey = document.getElementById("signerPublicKey").value;
    const signerWeight = document.getElementById("signerWeight").value;
    const StellarSdk = window.StellarSdk;
    const server = new StellarSdk.Horizon.Server(
        "https://horizon-testnet.stellar.org"
    );
 
    server
        .loadAccount(StellarSdk.Keypair.fromSecret(accountSecret).publicKey())
        .then((account) => {
            const transaction = new StellarSdk.TransactionBuilder(account, {
                fee: StellarSdk.BASE_FEE,
                networkPassphrase: StellarSdk.Networks.TESTNET,
            })
                .addOperation(
                    StellarSdk.Operation.setOptions({
                        signer: {
                            ed25519PublicKey: signerPublicKey,
                            weight: signerWeight,
                        },
                    })
                )
                .setTimeout(180)
                .build();
            transaction.sign(StellarSdk.Keypair.fromSecret(accountSecret));
            return server.submitTransaction(transaction);
        })
        .then((result) => {
            console.log("Success! Results:", result);
            alert("Signer added successfully!");
        })
        .catch((error) => {
            console.error("Something went wrong!", error);
            alert("Failed to add signer. Error: " + error.message);
        });
}

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.

Stellar CDN
*Current Version as of 2024-24-02*
<script src="https://cdnjs.cloudflare.com/ajax/libs/stellar-sdk/11.2.2/stellar-sdk.js"></script>
JavaScript
 
<script>
    function addSigner() {
    const accountSecret = document.getElementById('accountSecret').value;
    const signerPublicKey =
    document.getElementById('signerPublicKey').value;
    const signerWeight = document.getElementById('signerWeight').value;
    const StellarSdk = window.StellarSdk;
    const server = new StellarSdk.Horizon.Server('https://horizontestnet.stellar.org');
 
    server.loadAccount(StellarSdk.Keypair.fromSecret(accountSecret).publicKey())
    .then(account => {
    const transaction = new StellarSdk.TransactionBuilder(account, {
        fee: StellarSdk.BASE_FEE,
        networkPassphrase: StellarSdk.Networks.TESTNET
 })
    .addOperation(StellarSdk.Operation.setOptions({
        signer: {
        ed25519PublicKey: signerPublicKey,
        weight: signerWeight
 }
 }))
    .setTimeout(180)
    .build();
    transaction.sign(StellarSdk.Keypair.fromSecret(accountSecret));
    return server.submitTransaction(transaction);
 })
    .then(result => {
        console.log('Success! Results:', result);
        alert('Signer added successfully!');
 })
    .catch(error => {
        console.error('Something went wrong!', error);
        alert('Failed to add signer. Error: ' + error.message);
 });
 }
</script>
 
HTML
 
<body>
    <h2>Add Signer to Stellar Account</h2>
    <div>
        <input type="text" id="accountSecret" placeholder="Enter account secret
         key">
        <input type="text" id="signerPublicKey" placeholder="Enter signer public
        key">
        <input type="text" id="signerWeight" placeholder="Enter signer weight">
        <button onclick="addSigner()">Add Signer</button>
    </div>
</body>