You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This repository contains an example implementation of a [fungible token] contract in Rust which uses [near-contract-standards] and workspaces-rs tests.
1. Make sure Rust is installed per the prerequisites in [`near-sdk-rs`](https://github.com/near/near-sdk-rs#pre-requisites)
16
-
2. Ensure `near-cli` is installed by running `near --version`. If not installed, install with: `npm install -g near-cli`
14
+
## How to Build Locally?
17
15
18
-
## Building
16
+
Install [`cargo-near`](https://github.com/near/cargo-near) and run:
19
17
20
-
To build run:
21
18
```bash
22
-
./scripts/build.sh
19
+
cargo near build
23
20
```
24
21
25
-
Using this contract
26
-
===================
27
-
28
-
### Quickest deploy
29
-
30
-
You can build and deploy this smart contract to a development account. [Dev Accounts](https://docs.near.org/concepts/basics/account#dev-accounts) are auto-generated accounts to assist in developing and testing smart contracts. Please see the [Standard deploy](#standard-deploy) section for creating a more personalized account to deploy to.
22
+
## How to Test Locally?
31
23
32
24
```bash
33
-
near dev-deploy --wasmFile res/fungible_token.wasm --helperUrl https://near-contract-helper.onrender.com
25
+
cargo test
34
26
```
35
27
36
-
Behind the scenes, this is creating an account and deploying a contract to it. On the console, notice a message like:
28
+
## How to Deploy?
37
29
38
-
>Done deploying to dev-1234567890123
39
-
40
-
In this instance, the account is `dev-1234567890123`. A file has been created containing a key pair to
41
-
the account, located at `neardev/dev-account`. To make the next few steps easier, we're going to set an
42
-
environment variable containing this development account id and use that when copy/pasting commands.
43
-
Run this command to the environment variable:
30
+
To deploy manually, install [`cargo-near`](https://github.com/near/cargo-near) and run:
44
31
45
32
```bash
46
-
source neardev/dev-account.env
47
-
```
48
-
49
-
You can tell if the environment variable is set correctly if your command line prints the account name after this command:
50
-
```bash
51
-
echo$CONTRACT_NAME
52
-
```
33
+
# Create a new account
34
+
cargo near create-dev-account
53
35
54
-
The next command will initialize the contract using the `new` method:
This smart contract will get deployed to your NEAR account. For this example, please create a new NEAR account. Because NEAR allows the ability to upgrade contracts on the same account, initialization functions must be cleared. If you'd like to run this example on a NEAR account that has had prior contracts deployed, please use the `near-cli` command `near delete`, and then recreate it in Wallet. To create (or recreate) an account, please follow the directions on [NEAR Wallet](https://wallet.near.org/).
69
-
70
-
Switch to `mainnet`. You can skip this step to use `testnet` as a default network.
71
-
72
-
export NEAR_ENV=mainnet
73
-
74
-
In the project root, log in to your newly created account with `near-cli` by following the instructions after this command:
75
-
76
-
near login
77
-
78
-
To make this tutorial easier to copy/paste, we're going to set an environment variable for your account id. In the below command, replace `MY_ACCOUNT_NAME` with the account name you just logged in with, including the `.near`:
79
-
80
-
ID=MY_ACCOUNT_NAME
81
-
82
-
You can tell if the environment variable is set correctly if your command line prints the account name after this command:
83
-
84
-
echo $ID
85
-
86
-
Now we can deploy the compiled contract in this example to your account:
87
-
88
-
near deploy --wasmFile res/fungible_token.wasm --accountId $ID
89
-
90
-
FT contract should be initialized before usage. You can read more about metadata at ['nomicon.io'](https://nomicon.io/Standards/FungibleToken/Metadata.html#reference-level-explanation). Modify the parameters and create a token:
Check the balance of Bob again with the command from before and it will now return `19`.
121
-
122
-
## Testing
123
-
124
-
As with many Rust libraries and contracts, there are tests in the main fungible token implementation at `ft/src/lib.rs`.
125
-
126
-
Additionally, this project has [simulation] tests in `tests/sim`. Simulation tests allow testing cross-contract calls, which is crucial to ensuring that the `ft_transfer_call` function works properly. These simulation tests are the reason this project has the file structure it does. Note that the root project has a `Cargo.toml` which sets it up as a workspace. `ft` and `test-contract-defi` are both small & focused contract projects, the latter only existing for simulation tests. The root project imports `near-sdk-sim` and tests interaction between these contracts.
127
-
128
-
You can run unit tests with the following command:
129
-
130
-
```bash
131
-
cd ft && cargo test -- --nocapture --color=always
132
-
```
133
-
134
-
You can run integration tests with the following commands:
135
-
*Rust*
136
-
```bash
137
-
cd integration-tests/rs && cargo run --example integration-tests
@@ -147,14 +61,13 @@ cd integration-tests/ts && yarn && yarn test
147
61
- JSON calls should pass U128 as a base-10 string. E.g. "100".
148
62
- This does not include escrow functionality, as `ft_transfer_call` provides a superior approach. An escrow system can, of course, be added as a separate contract or additional functionality within this contract.
149
63
150
-
## No AssemblyScript?
151
-
152
-
[near-contract-standards] is currently Rust-only. We strongly suggest using this library to create your own Fungible Token contract to ensure it works as expected.
153
-
154
-
Someday NEAR core or community contributors may provide a similar library for AssemblyScript, at which point this example will be updated to include both a Rust and AssemblyScript version.
155
-
156
-
## Contributing
157
-
158
-
When making changes to the files in `ft` or `test-contract-defi`, remember to use `./build.sh` to compile all contracts and copy the output to the `res` folder. If you forget this, **the simulation tests will not use the latest versions**.
64
+
## Useful Links
159
65
160
-
Note that if the `rust-toolchain` file in this repository changes, please make sure to update the `.gitpod.Dockerfile` to explicitly specify using that as default as well.
66
+
-[cargo-near](https://github.com/near/cargo-near) - NEAR smart contract development toolkit for Rust
67
+
-[near CLI](https://near.cli.rs) - Iteract with NEAR blockchain from command line
0 commit comments