create-near-app 8.5.0 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.js +2 -1
- package/dist/make.js +7 -27
- package/dist/messages.js +1 -9
- package/dist/types.js +3 -2
- package/dist/user-input.js +32 -13
- package/dist/utils/index.js +1 -3
- package/package.json +2 -1
- package/templates/contracts/auction/rs/Cargo.toml +57 -0
- package/templates/contracts/auction/rs/README.md +39 -0
- package/templates/contracts/auction/rs/rust-toolchain.toml +4 -0
- package/templates/contracts/auction/rs/src/lib.rs +118 -0
- package/templates/contracts/auction/rs/tests/test_basics.rs +182 -0
- package/templates/contracts/auction/ts/README.md +47 -0
- package/templates/contracts/auction/ts/package.json +22 -0
- package/templates/contracts/auction/ts/sandbox-test/main.ava.js +88 -0
- package/templates/contracts/auction/ts/src/contract.ts +72 -0
- package/templates/contracts/auction/ts/tsconfig.json +14 -0
- package/templates/contracts/{rs → auction-adv/rs}/Cargo.toml +9 -7
- package/templates/contracts/auction-adv/rs/README.md +35 -0
- package/templates/contracts/{rs → auction-adv/rs}/rust-toolchain.toml +1 -1
- package/templates/contracts/auction-adv/rs/src/ext.rs +17 -0
- package/templates/contracts/auction-adv/rs/src/lib.rs +159 -0
- package/templates/contracts/auction-adv/rs/tests/fungible_token.wasm +0 -0
- package/templates/contracts/auction-adv/rs/tests/non_fungible_token.wasm +0 -0
- package/templates/contracts/auction-adv/rs/tests/test_basics.rs +430 -0
- package/templates/contracts/auction-adv/ts/README.md +45 -0
- package/templates/contracts/auction-adv/ts/package.json +22 -0
- package/templates/contracts/auction-adv/ts/sandbox-test/fungible_token.wasm +0 -0
- package/templates/contracts/auction-adv/ts/sandbox-test/main.ava.js +165 -0
- package/templates/contracts/auction-adv/ts/sandbox-test/non_fungible_token.wasm +0 -0
- package/templates/contracts/auction-adv/ts/src/contract.ts +87 -0
- package/templates/frontend/next-app/package.json +2 -28
- package/templates/frontend/next-app/src/app/hello-near/page.tsx +2 -4
- package/templates/frontend/next-app/src/app/layout.tsx +3 -58
- package/templates/frontend/next-app/src/components/navigation.tsx +14 -14
- package/templates/frontend/next-page/package.json +3 -24
- package/templates/frontend/next-page/src/components/cards.tsx +0 -1
- package/templates/frontend/next-page/src/components/navigation.tsx +14 -14
- package/templates/frontend/next-page/src/pages/_app.tsx +3 -56
- package/templates/frontend/next-page/src/pages/hello-near/index.tsx +2 -2
- package/templates/frontend/vite-react/package.json +6 -28
- package/templates/frontend/vite-react/src/App.tsx +3 -62
- package/templates/frontend/vite-react/src/components/navigation.tsx +13 -19
- package/templates/frontend/vite-react/src/global.d.ts +13 -0
- package/templates/frontend/vite-react/src/pages/hello_near.tsx +3 -3
- package/templates/contracts/py/.python-version +0 -1
- package/templates/contracts/py/README.md +0 -74
- package/templates/contracts/py/contract.py +0 -31
- package/templates/contracts/py/pyproject.toml +0 -10
- package/templates/contracts/py/tests/test_mod.py +0 -53
- package/templates/contracts/py/uv.lock +0 -878
- package/templates/contracts/rs/.github/workflows/deploy-production.yml +0 -25
- package/templates/contracts/rs/.github/workflows/deploy-staging.yml +0 -52
- package/templates/contracts/rs/.github/workflows/test.yml +0 -34
- package/templates/contracts/rs/.github/workflows/undeploy-staging.yml +0 -23
- package/templates/contracts/rs/README.md +0 -43
- package/templates/contracts/rs/src/lib.rs +0 -55
- package/templates/contracts/rs/tests/test_basics.rs +0 -30
- package/templates/contracts/ts/README.md +0 -83
- package/templates/contracts/ts/package.json +0 -23
- package/templates/contracts/ts/sandbox-test/main.ava.js +0 -45
- package/templates/contracts/ts/src/contract.ts +0 -23
- package/templates/contracts/ts/yarn.lock +0 -3290
- package/templates/frontend/next-app/src/wallets/web3modal.ts +0 -27
- package/templates/frontend/next-page/src/wallets/web3modal.ts +0 -27
- package/templates/frontend/vite-react/src/wallets/web3modal.ts +0 -27
- /package/templates/contracts/{ts → auction-adv/ts}/tsconfig.json +0 -0
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
name: Deploy to production
|
|
2
|
-
on:
|
|
3
|
-
push:
|
|
4
|
-
branches: [main]
|
|
5
|
-
|
|
6
|
-
jobs:
|
|
7
|
-
test:
|
|
8
|
-
uses: ./.github/workflows/test.yml
|
|
9
|
-
|
|
10
|
-
deploy-staging:
|
|
11
|
-
name: Deploy to production
|
|
12
|
-
needs: [test]
|
|
13
|
-
runs-on: ubuntu-latest
|
|
14
|
-
steps:
|
|
15
|
-
- name: Checkout repository
|
|
16
|
-
uses: actions/checkout@v4
|
|
17
|
-
- name: Install cargo-near CLI
|
|
18
|
-
run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/cargo-near/releases/latest/download/cargo-near-installer.sh | sh
|
|
19
|
-
- name: Deploy to production
|
|
20
|
-
run: |
|
|
21
|
-
cargo near deploy build-reproducible-wasm "${{ vars.NEAR_CONTRACT_PRODUCTION_ACCOUNT_ID }}" \
|
|
22
|
-
without-init-call \
|
|
23
|
-
network-config "${{ vars.NEAR_CONTRACT_PRODUCTION_NETWORK }}" \
|
|
24
|
-
sign-with-plaintext-private-key "${{ secrets.NEAR_CONTRACT_PRODUCTION_ACCOUNT_PRIVATE_KEY }}" \
|
|
25
|
-
send
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
name: Deploy to staging
|
|
2
|
-
on:
|
|
3
|
-
pull_request:
|
|
4
|
-
|
|
5
|
-
jobs:
|
|
6
|
-
test:
|
|
7
|
-
uses: ./.github/workflows/test.yml
|
|
8
|
-
|
|
9
|
-
deploy-staging:
|
|
10
|
-
name: Deploy to staging subaccount
|
|
11
|
-
permissions:
|
|
12
|
-
pull-requests: write
|
|
13
|
-
needs: [test]
|
|
14
|
-
runs-on: ubuntu-latest
|
|
15
|
-
env:
|
|
16
|
-
NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID: gh-${{ github.event.number }}.${{ vars.NEAR_CONTRACT_STAGING_ACCOUNT_ID }}
|
|
17
|
-
|
|
18
|
-
steps:
|
|
19
|
-
- name: Checkout repository
|
|
20
|
-
uses: actions/checkout@v4
|
|
21
|
-
|
|
22
|
-
- name: Install near CLI
|
|
23
|
-
run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/near-cli-rs/releases/download/v0.20.0/near-cli-rs-installer.sh | sh
|
|
24
|
-
- name: Create staging account
|
|
25
|
-
if: github.event.action == 'opened' || github.event.action == 'reopened'
|
|
26
|
-
run: |
|
|
27
|
-
near account create-account fund-myself "${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }}" '10 NEAR' \
|
|
28
|
-
use-manually-provided-public-key "${{ vars.NEAR_CONTRACT_STAGING_ACCOUNT_PUBLIC_KEY }}" \
|
|
29
|
-
sign-as "${{ vars.NEAR_CONTRACT_STAGING_ACCOUNT_ID }}" \
|
|
30
|
-
network-config "${{ vars.NEAR_CONTRACT_STAGING_NETWORK }}" \
|
|
31
|
-
sign-with-plaintext-private-key "${{ secrets.NEAR_CONTRACT_STAGING_ACCOUNT_PRIVATE_KEY }}" \
|
|
32
|
-
send
|
|
33
|
-
|
|
34
|
-
- name: Install cargo-near CLI
|
|
35
|
-
run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/cargo-near/releases/latest/download/cargo-near-installer.sh | sh
|
|
36
|
-
- name: Deploy to staging
|
|
37
|
-
# `--skip-git-remote-check` was used
|
|
38
|
-
# as pull request git refs `refs/pull/NUMBER/merge` are somewhat harder to access and live only as long as PRs do
|
|
39
|
-
#
|
|
40
|
-
# WASM reproducibility check akin to SourceScan won't be available for staging contracts, deployed from PRs
|
|
41
|
-
run: |
|
|
42
|
-
cargo near deploy build-reproducible-wasm --skip-git-remote-check "${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }}" \
|
|
43
|
-
without-init-call \
|
|
44
|
-
network-config "${{ vars.NEAR_CONTRACT_STAGING_NETWORK }}" \
|
|
45
|
-
sign-with-plaintext-private-key "${{ secrets.NEAR_CONTRACT_STAGING_ACCOUNT_PRIVATE_KEY }}" \
|
|
46
|
-
send
|
|
47
|
-
|
|
48
|
-
- name: Comment on pull request
|
|
49
|
-
env:
|
|
50
|
-
GH_TOKEN: ${{ github.token }}
|
|
51
|
-
run: |
|
|
52
|
-
gh pr comment "${{ github.event.number }}" --body "Staging contract is deployed to ["'`'"${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }}"'`'" account](https://explorer.${{ vars.NEAR_CONTRACT_STAGING_NETWORK }}.near.org/accounts/${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }})"
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
name: Test
|
|
2
|
-
on:
|
|
3
|
-
workflow_call:
|
|
4
|
-
|
|
5
|
-
jobs:
|
|
6
|
-
code-formatting:
|
|
7
|
-
name: Code Formatting
|
|
8
|
-
runs-on: ubuntu-latest
|
|
9
|
-
steps:
|
|
10
|
-
- name: Checkout repository
|
|
11
|
-
uses: actions/checkout@v4
|
|
12
|
-
- run: cargo fmt --check
|
|
13
|
-
|
|
14
|
-
code-linter:
|
|
15
|
-
name: Code Linter
|
|
16
|
-
runs-on: ubuntu-latest
|
|
17
|
-
steps:
|
|
18
|
-
- name: Checkout repository
|
|
19
|
-
uses: actions/checkout@v4
|
|
20
|
-
- name: Run cargo clippy
|
|
21
|
-
run: |
|
|
22
|
-
rustup component add clippy
|
|
23
|
-
cargo clippy --all-features --workspace --tests -- --warn clippy::all --warn clippy::nursery
|
|
24
|
-
|
|
25
|
-
tests:
|
|
26
|
-
name: Tests
|
|
27
|
-
runs-on: ubuntu-latest
|
|
28
|
-
steps:
|
|
29
|
-
- name: Checkout repository
|
|
30
|
-
uses: actions/checkout@v4
|
|
31
|
-
- name: Install cargo-near CLI
|
|
32
|
-
run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/cargo-near/releases/download/cargo-near-vcargo-near-new-ci-tool-version-self/cargo-near-installer.sh | sh
|
|
33
|
-
- name: Run cargo test
|
|
34
|
-
run: cargo test
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
name: Undeploy staging
|
|
2
|
-
on:
|
|
3
|
-
pull_request:
|
|
4
|
-
types: [closed]
|
|
5
|
-
|
|
6
|
-
jobs:
|
|
7
|
-
cleanup-staging:
|
|
8
|
-
name: Cleanup staging account
|
|
9
|
-
runs-on: ubuntu-latest
|
|
10
|
-
env:
|
|
11
|
-
NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID: gh-${{ github.event.number }}.${{ vars.NEAR_CONTRACT_STAGING_ACCOUNT_ID }}
|
|
12
|
-
steps:
|
|
13
|
-
- name: Checkout repository
|
|
14
|
-
uses: actions/checkout@v4
|
|
15
|
-
- name: Install near CLI
|
|
16
|
-
run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/near-cli-rs/releases/download/v0.20.0/near-cli-rs-installer.sh | sh
|
|
17
|
-
- name: Remove staging account
|
|
18
|
-
run: |
|
|
19
|
-
near account delete-account "${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }}" \
|
|
20
|
-
beneficiary "${{ vars.NEAR_CONTRACT_STAGING_ACCOUNT_ID }}" \
|
|
21
|
-
network-config "${{ vars.NEAR_CONTRACT_STAGING_NETWORK }}" \
|
|
22
|
-
sign-with-plaintext-private-key "${{ secrets.NEAR_CONTRACT_STAGING_ACCOUNT_PRIVATE_KEY }}" \
|
|
23
|
-
send
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# hello-rs
|
|
2
|
-
|
|
3
|
-
cargo-near-new-project-description
|
|
4
|
-
|
|
5
|
-
## How to Build Locally?
|
|
6
|
-
|
|
7
|
-
Install [`cargo-near`](https://github.com/near/cargo-near) and run:
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
cargo near build
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## How to Test Locally?
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
cargo test
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## How to Deploy?
|
|
20
|
-
|
|
21
|
-
Deployment is automated with GitHub Actions CI/CD pipeline.
|
|
22
|
-
To deploy manually, install [`cargo-near`](https://github.com/near/cargo-near) and run:
|
|
23
|
-
|
|
24
|
-
If you deploy for debugging purposes:
|
|
25
|
-
```bash
|
|
26
|
-
cargo near deploy build-non-reproducible-wasm <account-id>
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
If you deploy a production ready smart contract:
|
|
30
|
-
```bash
|
|
31
|
-
cargo near deploy build-reproducible-wasm <account-id>
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## Useful Links
|
|
35
|
-
|
|
36
|
-
- [cargo-near](https://github.com/near/cargo-near) - NEAR smart contract development toolkit for Rust
|
|
37
|
-
- [near CLI](https://near.cli.rs) - Interact with NEAR blockchain from command line
|
|
38
|
-
- [NEAR Rust SDK Documentation](https://docs.near.org/sdk/rust/introduction)
|
|
39
|
-
- [NEAR Documentation](https://docs.near.org)
|
|
40
|
-
- [NEAR StackOverflow](https://stackoverflow.com/questions/tagged/nearprotocol)
|
|
41
|
-
- [NEAR Discord](https://near.chat)
|
|
42
|
-
- [NEAR Telegram Developers Community Group](https://t.me/neardev)
|
|
43
|
-
- NEAR DevHub: [Telegram](https://t.me/neardevhub), [Twitter](https://twitter.com/neardevhub)
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
// Find all our documentation at https://docs.near.org
|
|
2
|
-
use near_sdk::{log, near};
|
|
3
|
-
|
|
4
|
-
// Define the contract structure
|
|
5
|
-
#[near(contract_state)]
|
|
6
|
-
pub struct Contract {
|
|
7
|
-
greeting: String,
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
// Define the default, which automatically initializes the contract
|
|
11
|
-
impl Default for Contract {
|
|
12
|
-
fn default() -> Self {
|
|
13
|
-
Self {
|
|
14
|
-
greeting: "Hello".to_string(),
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// Implement the contract structure
|
|
20
|
-
#[near]
|
|
21
|
-
impl Contract {
|
|
22
|
-
// Public method - returns the greeting saved, defaulting to DEFAULT_GREETING
|
|
23
|
-
pub fn get_greeting(&self) -> String {
|
|
24
|
-
self.greeting.clone()
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Public method - accepts a greeting, such as "howdy", and records it
|
|
28
|
-
pub fn set_greeting(&mut self, greeting: String) {
|
|
29
|
-
log!("Saving greeting: {greeting}");
|
|
30
|
-
self.greeting = greeting;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/*
|
|
35
|
-
* The rest of this file holds the inline tests for the code above
|
|
36
|
-
* Learn more about Rust tests: https://doc.rust-lang.org/book/ch11-01-writing-tests.html
|
|
37
|
-
*/
|
|
38
|
-
#[cfg(test)]
|
|
39
|
-
mod tests {
|
|
40
|
-
use super::*;
|
|
41
|
-
|
|
42
|
-
#[test]
|
|
43
|
-
fn get_default_greeting() {
|
|
44
|
-
let contract = Contract::default();
|
|
45
|
-
// this test did not call set_greeting so should return the default "Hello" greeting
|
|
46
|
-
assert_eq!(contract.get_greeting(), "Hello");
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
#[test]
|
|
50
|
-
fn set_then_get_greeting() {
|
|
51
|
-
let mut contract = Contract::default();
|
|
52
|
-
contract.set_greeting("howdy".to_string());
|
|
53
|
-
assert_eq!(contract.get_greeting(), "howdy");
|
|
54
|
-
}
|
|
55
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
use serde_json::json;
|
|
2
|
-
|
|
3
|
-
#[tokio::test]
|
|
4
|
-
async fn test_contract_is_operational() -> Result<(), Box<dyn std::error::Error>> {
|
|
5
|
-
let contract_wasm = near_workspaces::compile_project("./").await?;
|
|
6
|
-
|
|
7
|
-
test_basics_on(&contract_wasm).await?;
|
|
8
|
-
Ok(())
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
async fn test_basics_on(contract_wasm: &[u8]) -> Result<(), Box<dyn std::error::Error>> {
|
|
12
|
-
let sandbox = near_workspaces::sandbox().await?;
|
|
13
|
-
let contract = sandbox.dev_deploy(contract_wasm).await?;
|
|
14
|
-
|
|
15
|
-
let user_account = sandbox.dev_create_account().await?;
|
|
16
|
-
|
|
17
|
-
let outcome = user_account
|
|
18
|
-
.call(contract.id(), "set_greeting")
|
|
19
|
-
.args_json(json!({"greeting": "Hello World!"}))
|
|
20
|
-
.transact()
|
|
21
|
-
.await?;
|
|
22
|
-
assert!(outcome.is_success());
|
|
23
|
-
|
|
24
|
-
let user_message_outcome = contract.view("get_greeting").args_json(json!({})).await?;
|
|
25
|
-
assert_eq!(user_message_outcome.json::<String>()?, "Hello World!");
|
|
26
|
-
|
|
27
|
-
Ok(())
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
# Hello NEAR Contract
|
|
2
|
-
|
|
3
|
-
The smart contract exposes two methods to enable storing and retrieving a greeting in the NEAR network.
|
|
4
|
-
|
|
5
|
-
```ts
|
|
6
|
-
@NearBindgen({})
|
|
7
|
-
class HelloNear {
|
|
8
|
-
greeting: string = "Hello";
|
|
9
|
-
|
|
10
|
-
@view // This method is read-only and can be called for free
|
|
11
|
-
get_greeting(): string {
|
|
12
|
-
return this.greeting;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
@call // This method changes the state, for which it cost gas
|
|
16
|
-
set_greeting({ greeting }: { greeting: string }): void {
|
|
17
|
-
// Record a log permanently to the blockchain!
|
|
18
|
-
near.log(`Saving greeting ${greeting}`);
|
|
19
|
-
this.greeting = greeting;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
<br />
|
|
25
|
-
|
|
26
|
-
# Quickstart
|
|
27
|
-
|
|
28
|
-
1. Make sure you have installed [node.js](https://nodejs.org/en/download/package-manager/) >= 16.
|
|
29
|
-
2. Install the [`NEAR CLI`](https://github.com/near/near-cli#setup)
|
|
30
|
-
|
|
31
|
-
<br />
|
|
32
|
-
|
|
33
|
-
## 1. Build and Test the Contract
|
|
34
|
-
You can automatically compile and test the contract by running:
|
|
35
|
-
|
|
36
|
-
```bash
|
|
37
|
-
npm run build
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
<br />
|
|
41
|
-
|
|
42
|
-
## 2. Create an Account and Deploy the Contract
|
|
43
|
-
You can create a new account and deploy the contract by running:
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
near create-account <your-account.testnet> --useFaucet
|
|
47
|
-
near deploy <your-account.testnet> build/release/hello_near.wasm
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
<br />
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
## 3. Retrieve the Greeting
|
|
54
|
-
|
|
55
|
-
`get_greeting` is a read-only method (aka `view` method).
|
|
56
|
-
|
|
57
|
-
`View` methods can be called for **free** by anyone, even people **without a NEAR account**!
|
|
58
|
-
|
|
59
|
-
```bash
|
|
60
|
-
# Use near-cli to get the greeting
|
|
61
|
-
near view <your-account.testnet> get_greeting
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
<br />
|
|
65
|
-
|
|
66
|
-
## 4. Store a New Greeting
|
|
67
|
-
`set_greeting` changes the contract's state, for which it is a `call` method.
|
|
68
|
-
|
|
69
|
-
`Call` methods can only be invoked using a NEAR account, since the account needs to pay GAS for the transaction.
|
|
70
|
-
|
|
71
|
-
```bash
|
|
72
|
-
# Use near-cli to set a new greeting
|
|
73
|
-
near call <your-account.testnet> set_greeting '{"greeting":"howdy"}' --accountId <your-account.testnet>
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
**Tip:** If you would like to call `set_greeting` using another account, first login into NEAR using:
|
|
77
|
-
|
|
78
|
-
```bash
|
|
79
|
-
# Use near-cli to login your NEAR account
|
|
80
|
-
near login
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
and then use the logged account to sign the transaction: `--accountId <another-account>`.
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "hello_near",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"license": "(MIT AND Apache-2.0)",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"build": "near-sdk-js build src/contract.ts build/hello_near.wasm",
|
|
8
|
-
"test": "$npm_execpath run build && ava -- ./build/hello_near.wasm"
|
|
9
|
-
},
|
|
10
|
-
"dependencies": {
|
|
11
|
-
"near-sdk-js": "2.0.0"
|
|
12
|
-
},
|
|
13
|
-
"devDependencies": {
|
|
14
|
-
"ava": "^6.1.3",
|
|
15
|
-
"near-workspaces": "^4.0.0",
|
|
16
|
-
"typescript": "^5.4.5"
|
|
17
|
-
},
|
|
18
|
-
"ava": {
|
|
19
|
-
"files": [
|
|
20
|
-
"sandbox-test/*.ava.js"
|
|
21
|
-
]
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import anyTest from 'ava';
|
|
2
|
-
import { Worker } from 'near-workspaces';
|
|
3
|
-
import { setDefaultResultOrder } from 'dns'; setDefaultResultOrder('ipv4first'); // temp fix for node >v17
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @typedef {import('near-workspaces').NearAccount} NearAccount
|
|
7
|
-
* @type {import('ava').TestFn<{worker: Worker, accounts: Record<string, NearAccount>}>}
|
|
8
|
-
*/
|
|
9
|
-
const test = anyTest;
|
|
10
|
-
|
|
11
|
-
test.beforeEach(async t => {
|
|
12
|
-
// Create sandbox
|
|
13
|
-
const worker = t.context.worker = await Worker.init();
|
|
14
|
-
|
|
15
|
-
// Deploy contract
|
|
16
|
-
const root = worker.rootAccount;
|
|
17
|
-
const contract = await root.createSubAccount('test-account');
|
|
18
|
-
|
|
19
|
-
// Get wasm file path from package.json test script in folder above
|
|
20
|
-
await contract.deploy(
|
|
21
|
-
process.argv[2],
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
// Save state for test runs, it is unique for each test
|
|
25
|
-
t.context.accounts = { root, contract };
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test.afterEach.always(async (t) => {
|
|
29
|
-
await t.context.worker.tearDown().catch((error) => {
|
|
30
|
-
console.log('Failed to stop the Sandbox:', error);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test('returns the default greeting', async (t) => {
|
|
35
|
-
const { contract } = t.context.accounts;
|
|
36
|
-
const greeting = await contract.view('get_greeting', {});
|
|
37
|
-
t.is(greeting, 'Hello');
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test('changes the greeting', async (t) => {
|
|
41
|
-
const { root, contract } = t.context.accounts;
|
|
42
|
-
await root.call(contract, 'set_greeting', { greeting: 'Howdy' });
|
|
43
|
-
const greeting = await contract.view('get_greeting', {});
|
|
44
|
-
t.is(greeting, 'Howdy');
|
|
45
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// Find all our documentation at https://docs.near.org
|
|
2
|
-
import { NearBindgen, near, call, view } from 'near-sdk-js';
|
|
3
|
-
|
|
4
|
-
@NearBindgen({})
|
|
5
|
-
class HelloNear {
|
|
6
|
-
|
|
7
|
-
static schema = {
|
|
8
|
-
greeting: 'string'
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
greeting: string = 'Hello';
|
|
12
|
-
|
|
13
|
-
@view({}) // This method is read-only and can be called for free
|
|
14
|
-
get_greeting(): string {
|
|
15
|
-
return this.greeting;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
@call({}) // This method changes the state, for which it cost gas
|
|
19
|
-
set_greeting({ greeting }: { greeting: string }): void {
|
|
20
|
-
near.log(`Saving greeting ${greeting}`);
|
|
21
|
-
this.greeting = greeting;
|
|
22
|
-
}
|
|
23
|
-
}
|