Configuración
Los contratos inteligentes Stellar son pequeños programas escritos en el lenguaje de programación Rust.
Para crear y desarrollar contratos, necesitas los siguientes requisitos previos:
- Una cadena de herramientas de Rust
- Un editor que admita Rust
- Stellar CLI
Instalar Rust
- macOS/Linux
- Windows
- Otro
Si usa macOS, Linux u otro sistema operativo tipo Unix, el método más simple para instalar una toolchain de Rust es instalar rustup
. Instala rustup
con el siguiente comando.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Luego reinicia la terminal.
En Windows, descarga y ejecuta rustup-init.exe. Puedes continuar con la configuración predeterminada presionando Enter.
El Stellar CLI usa emojis en su salida. Para renderizarlos correctamente en Windows, se recomienda usar el Windows Terminal. Consulta cómo instalar Windows Terminal en Microsoft Learn. Si se usa la CLI en la ventana de comandos de Windows o en PowerShell, funcionará como se espera, pero los emojis aparecerán como signos de interrogación.
Si ya estás usando WSL, también puedes seguir las instrucciones para Linux.
Para otros métodos de instalación de Rust, consulta: https://www.rust-lang.org/tools/install
Instalar el objetivo
You'll need a "target" for which your smart contract will be compiled. Para Rust v1.84.0
o superior, instala el target wasm32v1-none
.
rustup target add wasm32v1-none
Puedes aprender más sobre los detalles que aporta este target en nuestra página dedicada al dialecto Stellar Rust. Esta página describe el subconjunto de funcionalidades de Rust que tienes disponibles dentro del entorno de contratos inteligentes de Stellar.
Configurar un editor
Many editors have support for Rust. Visit the following link to find out how to configure your editor: https://www.rust-lang.org/tools
Estas son las herramientas que necesitas para configurar tu editor:
- Visual Studio Code como editor de código (u otro editor que soporte Rust)
- Rust Analyzer para soporte del lenguaje Rust
- CodeLLDB para depuración paso a paso
Install the Stellar CLI
The Stellar CLI can execute smart contracts on futurenet, testnet, mainnet, as well as in a local sandbox.
La última versión estable es v23.1.4.
Install
There are a few ways to install the latest release of Stellar CLI.
- macOS
- Linux
- Windows
Install with Homebrew (macOS, Linux):
brew install stellar-cli
Install with cargo from source:
cargo install --locked [email protected]
Instalar con Homebrew (macOS, Linux):
brew install stellar-cli
Install with cargo from source:
cargo install --locked [email protected]
Instalar desde el código fuente requiere un sistema de compilación en C. Para instalar un sistema de compilación en C en Debian/Ubuntu, usa:
sudo apt update && sudo apt install -y build-essential
Using the installer:
- Download the installer from the latest release.
- Go to your Downloads folder, double click the installer and follow the wizard instructions.
- Restart your terminal to use the
stellar
command.
Using winget:
winget install --id Stellar.StellarCLI --version 23.1.4
Instalar con cargo desde el código fuente:
cargo install --locked [email protected]
Report issues and share feedback about the Stellar CLI here.
Documentation
La documentación de referencia completa autogenerada está disponible aquí.
Autocompletion
You can use stellar completion
to generate shell completion for different shells. You should absolutely try it out. It will feel like a super power!
- Bash
- ZSH
- fish
- PowerShell
- Elvish
Para habilitar el autocompletado en la sesión actual del shell:
source <(stellar completion --shell bash)
To enable autocomplete permanently, run the following command, then restart your terminal:
echo "source <(stellar completion --shell bash)" >> ~/.bashrc
Para habilitar el autocompletado en la sesión actual del shell:
source <(stellar completion --shell zsh)
To enable autocomplete permanently, run the following commands, then restart your terminal:
echo "source <(stellar completion --shell zsh)" >> ~/.zshrc
To enable autocomplete on the current shell session:
stellar completion --shell fish | source
To enable autocomplete permanently, run the following command, then restart your terminal:
echo "stellar completion --shell fish | source" >> ~/.config/fish/config.fish
Para habilitar el autocompletado en la sesión actual del shell:
stellar completion --shell powershell | Out-String | Invoke-Expression
To enable autocomplete permanently, run the following commands, then restart your terminal:
New-Item -ItemType Directory -Path $(Split-Path $PROFILE) -Force
if (-Not (Test-Path $PROFILE)) { New-Item -ItemType File -Path $PROFILE | Out-Null }
Add-Content $PROFILE 'Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete'
Add-Content $PROFILE 'stellar completion --shell powershell | Out-String | Invoke-Expression'
If you get an error like cannot be loaded because running scripts is disabled on this system
, you may need to change your Execution Policy with Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser
. Before running this command, be sure you understand the implications of doing so.
Para habilitar el autocompletado en la sesión actual del shell:
source (stellar completion --shell elvish)
Para habilitar el autocompletado de forma permanente, ejecuta los siguientes comandos y luego reinicia tu terminal:
echo "source (stellar completion --shell elvish)" >> ~/.elvish/rc.elv
Configuring the CLI for Testnet
Configure an Identity
When you deploy a smart contract to a network, you need to specify an identity that will be used to sign the transactions.
Let's configure an identity called alice
. You can use any name you want, but it might be nice to have some named identities that you can use for testing, such as alice
, bob
, and carol
. Notice that the account will be funded using Friendbot.
stellar keys generate alice --network testnet --fund
You can see the public key of alice
with:
stellar keys address alice
Like the Network configs, the --global
means that the identity gets stored in ~/.config/stellar/identity/alice.toml
. You can omit the --global
flag to store the identity in your project's .stellar/identity
folder instead.
We previously used ~/.config/soroban
(global) and .soroban
(local) as the configuration directories. These directories are still supported, but the preferred name is now ~/.config/stellar
and .stellar
moving forward.