Skip to content

Commit

Permalink
docs: Fixed broken links in README and updated cargo-near section (ne…
Browse files Browse the repository at this point in the history
  • Loading branch information
frol authored Mar 29, 2024
1 parent 9aa5eb0 commit 9793852
Showing 1 changed file with 77 additions and 15 deletions.
92 changes: 77 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

## Release notes

**Release notes and unreleased changes can be found in the [CHANGELOG](CHANGELOG.md)**
**Release notes and unreleased changes can be found in the [CHANGELOG](https://github.com/near/near-sdk-rs/blob/master/CHANGELOG.md)**

## Example

Expand Down Expand Up @@ -78,7 +78,7 @@ fn set_get_message() {
```

Run unit test the usual way:
```bash
```sh
cargo test --package status-message
```

Expand All @@ -89,7 +89,7 @@ Asynchronous cross-contract calls allow parallel execution of multiple contracts
* `promise_and` -- combinator, allows waiting on several promises simultaneously, before executing the callback;
* `promise_return` -- treats the result of execution of the promise as the result of the current function.

Follow [examples/cross-contract-high-level](examples/cross-contract-calls/high-level)
Follow [examples/cross-contract-high-level](https://github.com/near/near-sdk-rs/tree/master/examples/cross-contract-calls/high-level)
to see various usages of cross contract calls, including **system-level actions** done from inside the contract like balance transfer (examples of other system-level actions are: account creation, access key creation/deletion, contract deployment, etc).

### Initialization methods
Expand Down Expand Up @@ -165,19 +165,19 @@ Now, only the account of the contract itself can call this method, either direct
## Pre-requisites
To develop Rust contracts you would need to:
* Install [Rustup](https://rustup.rs/):
```bash
```sh
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```
* Add wasm target to your toolchain:
```bash
```sh
rustup target add wasm32-unknown-unknown
```

## Writing Rust Contract
You can follow the [examples/status-message](examples/status-message) crate that shows a simple Rust contract.
You can follow the [examples/status-message](https://github.com/near/near-sdk-rs/tree/master/examples/status-message) crate that shows a simple Rust contract.

The general workflow is the following:
1. Create a crate and configure the `Cargo.toml` similarly to how it is configured in [examples/status-message/Cargo.toml](examples/status-message/Cargo.toml);
1. Create a crate and configure the `Cargo.toml` similarly to how it is configured in [examples/status-message/Cargo.toml](https://github.com/near/near-sdk-rs/tree/master/examples/status-message/Cargo.toml);
2. Crate needs to have one `pub` struct that will represent the smart contract itself:
* The struct needs to implement `Default` trait which
NEAR will use to create the initial state of the contract upon its first usage;
Expand Down Expand Up @@ -216,19 +216,81 @@ The general workflow is the following:

### [cargo-near](https://github.com/near/cargo-near)

This can be used as an alternative, to allow building while also generating an [abi](https://github.com/near/abi)
`cargo-near` is an easy and recommended way to build and deploy Rust contracts.

```bash
# Install the near extension if you haven't already
#### Installation

<details>
<summary>Install prebuilt binaries via shell script (Linux, macOS)</summary>

```sh
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/cargo-near/releases/latest/download/cargo-near-installer.sh | sh
```
</details>

<details>
<summary>Install prebuilt binaries via powershell script (Windows)</summary>

```sh
irm https://github.com/near/cargo-near/releases/latest/download/cargo-near-installer.ps1 | iex
```
</details>

<details>
<summary>Install prebuilt binaries into your Node.js application</summary>

```sh
npm install cargo-near
```
</details>

<details>
<summary>Compile and install from source code (Cargo)</summary>

```sh
cargo install cargo-near
```

or, install the most recent version from git repository:

# Builds the wasm contract and ABI into `target/near`
cargo near build --release
```sh
$ git clone https://github.com/near/cargo-near
$ cargo install --path cargo-near
```
</details>

#### Usage

See `cargo near --help` for a complete list of available commands or run `cargo near` to dive into interactive mode.
Help is also available for each individual command with a `--help` flag, e.g. `cargo near build --help`.

```sh
cargo near
```

Starts interactive mode that will allow to explore all the available commands.

```sh
cargo near build
```

Builds a NEAR smart contract along with its [ABI](https://github.com/near/abi) (while in the directory containing contract's Cargo.toml).

```sh
cargo near create-dev-account
```

Guides you through creation of a new NEAR account on [testnet](https://explorer.testnet.near.org).

```sh
cargo near deploy
```

Builds the smart contract (equivalent to `cargo near build`) and guides you to deploy it to the blockchain.

### Using cargo build

```bash
```sh
RUSTFLAGS='-C link-arg=-s' cargo build --target wasm32-unknown-unknown --release
```

Expand All @@ -245,8 +307,8 @@ that allows to compile the binary.
[`near-contract-standards` crate](https://github.com/near/near-sdk-rs/tree/master/near-contract-standards) provides a set of interfaces and implementations for NEAR's contract standards:

- Upgradability
- Fungible Token (NEP-141). See [example usage](examples/fungible-token)
- Non-Fungible Token (NEP-171). See [example usage](examples/non-fungible-token)
- Fungible Token (NEP-141). See [example usage](https://github.com/near/near-sdk-rs/tree/master/examples/fungible-token)
- Non-Fungible Token (NEP-171). See [example usage](https://github.com/near/near-sdk-rs/tree/master/examples/non-fungible-token)


## Versioning
Expand Down

0 comments on commit 9793852

Please sign in to comment.