Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 3 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,4 @@
# Welcome
Welcome to this tutorial for learning how to make your own NEAR contract using rust.
# Sobre el proyecto
En este proyecto vamos a aprender a hacer contratos de NEAR con rust. Para esto, se aconseja seguir las instrucciones que se dan en los distintos archivos dentro de la carpeta `readmes/`. Están nombrados por versión, donde en cada caso se enseña algo nuevo.

For this tutorial we will be using rustc 1.80.1 (3f5fd8dd4 2024-08-06)

This tutorial will asume you know some things and have installed some others.

## Installing necessary packages
### Rust
For installing rust, follow the instructions in this [link](https://www.rust-lang.org/tools/install)

This will install the most recent version of rust. Currently, NEAR is having some issues with the most recent version of rust. For this, we recommend you to downgrade to the version for this tutorial the following way

```
rustup install 1.80.1
rustup default 1.80.1
```

You can check it running `rustc --version`

### Other packages
You can follow the instructions in the [NEAR documentation](https://docs.near.org/smart-contracts/quickstart). Just in case the contents change, we will paste the most relevant commands

```
# Contracts will be compiled to wasm, so we need to add the wasm target
rustup target add wasm32-unknown-unknown

# Install NEAR CLI-RS to deploy and interact with the contract
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/near-cli-rs/releases/latest/download/near-cli-rs-installer.sh | sh

# Install cargo near to help building the contract
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/cargo-near/releases/latest/download/cargo-near-installer.sh | sh
```

## Initialize your contract
With the following command we will have a basic NEAR contract ready for deployment with basic tests as well. This command will generate a `hello-near` folder.
```
cargo near new hello-near
```

After this, we can check on `src/lib.rs` our contract with a set_greeting and get_greeting function and their corresponding tests.

## Test your contract
### Using rust
Besides the mentioned tests, we have one more test on `tests/test_basics.rs`. If we want to run our rust tests, we can do it by simply running:
```
cargo test
```

After running this command, the code will be compiled into a `target/` folder on the root of the project. Note this folder is included on the `.gitignore` file, so it is not necessary nor convinient to be shared in github, since we can generate it very easily.

There are 2 types of tests on rust:
- Infile tests: tests that are written in a file and are supposed to test the functions defined on that file;
- Integration tests: written typically on a `tests` folder on the root of the project and should tests integrally the whole contract.

## What else is relevant?
We also have the `Cargo.toml` file which is like the `package.json` file for node. We can include some configuration and our dependencies. We can search for dependencies in `https://crates.io/`.
Para cada readme hay un branch con el nombre correspondiente. En cada branch, se hacen los cambios que se describen en el readme, agregando archivos y cambiando o agregando código. Se aconseja empezar con el instructivo en el branch v1 y seguir a partir de ahí.
56 changes: 56 additions & 0 deletions readmes/v1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Bienvenidos
Bienvenidos a este tutorial para aprender a hacer tu propio contrato de NEAR utilizando rust.

Para este tutorial, vamos a utilizar la versión 1.80.1 de rustc

En este tutorial, se va a asumir cierto nivel de conocimiento y que se tienen ciertas cosas instaladas, como node y un manejo básico del mismo.

## Instalando los paquetes necesarios
### Rust
Para instalar rust, sigan las instrucciones en el [sitio oficial de rust](https://www.rust-lang.org/tools/install)

Esto va a instalar la versión más reciente de rust. En este momento, NEAR está teniendo ciertos problemas con la versión más reciente de rust. Por esto, les recomendamos que bajen la versión de rust para este tutorial de la siguiente forma:

```
rustup install 1.80.1
rustup default 1.80.1
```

Pueden verificarlo corriendo `rustc --version`

### Otros paquetes
Pueden seguir las siguientes instrucciones en la [documentación de NEAR](https://docs.near.org/smart-contracts/quickstart). En caso que el contenido de la página cambie, se pegan los comandos más relevantes abajo.

```
# Contracts will be compiled to wasm, so we need to add the wasm target
rustup target add wasm32-unknown-unknown

# Install NEAR CLI-RS to deploy and interact with the contract
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/near-cli-rs/releases/latest/download/near-cli-rs-installer.sh | sh

# Install cargo near to help building the contract
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/cargo-near/releases/latest/download/cargo-near-installer.sh | sh
```

## Inicializar el código del contrato
Con el siguiente comando vamos a tener un contrato básico de NEAR listo para ser deployado con unos tests básicos. Esto también nos va a generar una carpeta `hello-near`.
```
cargo near new hello-near
```

Luego de esto, podemos verificar en `src/lib.rs` nuestro contrato con las funciones set_greeting y get_greeting y sus tests correspondientes.

## Testear tu contrato
Además de los tests unitarios mencionados, tenemos un test más en `tests/test_basics.rs`. Si queremos correr los tests, podemos hacerlo simplemente corriendo:
```
cargo test
```

Luego de correr este comando, el código será compilado en la carpeta `target/` en la raiz del proyecto. Noten que esta carpeta ya está incluida en el archivo `.gitignore`, por lo que no es necesario ni conveniente subir esta carpeta a github, ya que se puede generar con mucha facilidad.

Hay 2 tipos de tests en rust:
- Tests en el archivo: los tests son escritos en el mismo archivo que tienen las funciones que deben ser testeadas
- Tests de integración: generalmente escritos en la carpeta `tests/` que se encuentra en la raiz del proyecto y deberían testear todo el contrato.

## ¿Qué más es importante?
También tenemos el archivo `Cargo.toml` que es como el `package.json` en node. Podemos incluir cierta configuración y nuestras dependencias. Podemos buscar dependencias en `https://crates.io/`.
Loading