create-near-app 8.4.1 → 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.
Files changed (92) hide show
  1. package/dist/app.js +2 -1
  2. package/dist/make.js +7 -27
  3. package/dist/messages.js +1 -9
  4. package/dist/types.js +3 -2
  5. package/dist/user-input.js +32 -13
  6. package/dist/utils/index.js +1 -3
  7. package/package.json +2 -1
  8. package/templates/contracts/auction/rs/Cargo.toml +57 -0
  9. package/templates/contracts/auction/rs/README.md +39 -0
  10. package/templates/contracts/auction/rs/rust-toolchain.toml +4 -0
  11. package/templates/contracts/auction/rs/src/lib.rs +118 -0
  12. package/templates/contracts/auction/rs/tests/test_basics.rs +182 -0
  13. package/templates/contracts/auction/ts/README.md +47 -0
  14. package/templates/contracts/auction/ts/package.json +22 -0
  15. package/templates/contracts/auction/ts/sandbox-test/main.ava.js +88 -0
  16. package/templates/contracts/auction/ts/src/contract.ts +72 -0
  17. package/templates/contracts/auction/ts/tsconfig.json +14 -0
  18. package/templates/contracts/{rs → auction-adv/rs}/Cargo.toml +9 -7
  19. package/templates/contracts/auction-adv/rs/README.md +35 -0
  20. package/templates/contracts/{rs → auction-adv/rs}/rust-toolchain.toml +1 -1
  21. package/templates/contracts/auction-adv/rs/src/ext.rs +17 -0
  22. package/templates/contracts/auction-adv/rs/src/lib.rs +159 -0
  23. package/templates/contracts/auction-adv/rs/tests/fungible_token.wasm +0 -0
  24. package/templates/contracts/auction-adv/rs/tests/non_fungible_token.wasm +0 -0
  25. package/templates/contracts/auction-adv/rs/tests/test_basics.rs +430 -0
  26. package/templates/contracts/auction-adv/ts/README.md +45 -0
  27. package/templates/contracts/auction-adv/ts/package.json +22 -0
  28. package/templates/contracts/auction-adv/ts/sandbox-test/fungible_token.wasm +0 -0
  29. package/templates/contracts/auction-adv/ts/sandbox-test/main.ava.js +165 -0
  30. package/templates/contracts/auction-adv/ts/sandbox-test/non_fungible_token.wasm +0 -0
  31. package/templates/contracts/auction-adv/ts/src/contract.ts +87 -0
  32. package/templates/frontend/next-app/next-env.d.ts +6 -0
  33. package/templates/frontend/next-app/package.json +8 -22
  34. package/templates/frontend/{next-page/src/pages/hello-near/index.js → next-app/src/app/hello-near/page.tsx} +22 -21
  35. package/templates/frontend/next-app/src/app/layout.tsx +25 -0
  36. package/templates/frontend/next-app/src/components/{cards.js → cards.tsx} +4 -9
  37. package/templates/frontend/next-app/src/components/navigation.tsx +45 -0
  38. package/templates/frontend/next-app/tsconfig.json +42 -0
  39. package/templates/frontend/next-page/next-env.d.ts +6 -0
  40. package/templates/frontend/next-page/package.json +8 -22
  41. package/templates/frontend/next-page/src/components/{cards.js → cards.tsx} +0 -1
  42. package/templates/frontend/next-page/src/components/navigation.tsx +45 -0
  43. package/templates/frontend/next-page/src/pages/_app.tsx +15 -0
  44. package/templates/frontend/{vite-react/src/pages/hello_near.jsx → next-page/src/pages/hello-near/index.tsx} +18 -16
  45. package/templates/frontend/next-page/src/pages/{index.js → index.tsx} +8 -8
  46. package/templates/frontend/next-page/tsconfig.json +35 -0
  47. package/templates/frontend/vite-react/eslint.config.js +4 -1
  48. package/templates/frontend/vite-react/package.json +8 -25
  49. package/templates/frontend/vite-react/src/App.tsx +22 -0
  50. package/templates/frontend/vite-react/src/components/{cards.jsx → cards.tsx} +4 -4
  51. package/templates/frontend/vite-react/src/components/navigation.tsx +43 -0
  52. package/templates/frontend/vite-react/src/{config.js → config.ts} +1 -1
  53. package/templates/frontend/vite-react/src/global.d.ts +13 -0
  54. package/templates/frontend/vite-react/src/main.tsx +14 -0
  55. package/templates/frontend/vite-react/src/pages/hello_near.tsx +95 -0
  56. package/templates/frontend/vite-react/tsconfig.json +35 -0
  57. package/templates/contracts/py/.python-version +0 -1
  58. package/templates/contracts/py/README.md +0 -74
  59. package/templates/contracts/py/contract.py +0 -31
  60. package/templates/contracts/py/pyproject.toml +0 -10
  61. package/templates/contracts/py/tests/test_mod.py +0 -53
  62. package/templates/contracts/py/uv.lock +0 -878
  63. package/templates/contracts/rs/.github/workflows/deploy-production.yml +0 -25
  64. package/templates/contracts/rs/.github/workflows/deploy-staging.yml +0 -52
  65. package/templates/contracts/rs/.github/workflows/test.yml +0 -34
  66. package/templates/contracts/rs/.github/workflows/undeploy-staging.yml +0 -23
  67. package/templates/contracts/rs/README.md +0 -43
  68. package/templates/contracts/rs/src/lib.rs +0 -55
  69. package/templates/contracts/rs/tests/test_basics.rs +0 -30
  70. package/templates/contracts/ts/README.md +0 -83
  71. package/templates/contracts/ts/package.json +0 -23
  72. package/templates/contracts/ts/sandbox-test/main.ava.js +0 -45
  73. package/templates/contracts/ts/src/contract.ts +0 -23
  74. package/templates/contracts/ts/yarn.lock +0 -3290
  75. package/templates/frontend/next-app/jsconfig.json +0 -7
  76. package/templates/frontend/next-app/src/app/hello-near/page.js +0 -67
  77. package/templates/frontend/next-app/src/app/layout.js +0 -54
  78. package/templates/frontend/next-app/src/components/navigation.js +0 -35
  79. package/templates/frontend/next-app/src/wallets/web3modal.js +0 -27
  80. package/templates/frontend/next-page/jsconfig.json +0 -7
  81. package/templates/frontend/next-page/src/components/navigation.js +0 -35
  82. package/templates/frontend/next-page/src/pages/_app.js +0 -45
  83. package/templates/frontend/next-page/src/wallets/web3modal.js +0 -27
  84. package/templates/frontend/vite-react/src/App.jsx +0 -56
  85. package/templates/frontend/vite-react/src/components/navigation.jsx +0 -37
  86. package/templates/frontend/vite-react/src/main.jsx +0 -11
  87. package/templates/frontend/vite-react/src/wallets/web3modal.js +0 -27
  88. /package/templates/contracts/{ts → auction-adv/ts}/tsconfig.json +0 -0
  89. /package/templates/frontend/next-app/src/app/{page.js → page.tsx} +0 -0
  90. /package/templates/frontend/next-app/src/{config.js → config.ts} +0 -0
  91. /package/templates/frontend/next-page/src/{config.js → config.ts} +0 -0
  92. /package/templates/frontend/vite-react/src/pages/{home.jsx → home.tsx} +0 -0
@@ -9,42 +9,25 @@
9
9
  "preview": "vite preview"
10
10
  },
11
11
  "dependencies": {
12
- "@near-wallet-selector/bitte-wallet": "^9.0.1",
13
- "@near-wallet-selector/core": "^9.0.1",
14
- "@near-wallet-selector/ethereum-wallets": "^9.0.1",
15
- "@near-wallet-selector/here-wallet": "^9.0.1",
16
- "@near-wallet-selector/hot-wallet": "^9.0.1",
17
- "@near-wallet-selector/ledger": "^9.0.1",
18
- "@near-wallet-selector/meteor-wallet": "^9.0.1",
19
- "@near-wallet-selector/meteor-wallet-app": "^9.0.1",
20
- "@near-wallet-selector/modal-ui": "^9.0.1",
21
- "@near-wallet-selector/my-near-wallet": "^9.0.1",
22
- "@near-wallet-selector/near-mobile-wallet": "^9.0.1",
23
- "@near-wallet-selector/react-hook": "^9.0.1",
24
- "@near-wallet-selector/sender": "^9.0.1",
25
- "@near-wallet-selector/welldone-wallet": "^9.0.1",
26
- "@reown/appkit": "^1.7.4",
27
- "@reown/appkit-adapter-wagmi": "^1.7.4",
28
- "@wagmi/core": "^2.17.1",
29
12
  "bootstrap": "^5",
30
13
  "bootstrap-icons": "^1.11.3",
31
- "near-api-js": "^5.1.1",
32
- "react": "^18",
33
- "react-dom": "^18",
34
- "react-router": "^7",
35
- "viem": "^2.30.5"
14
+ "near-connect-hooks": "^1.0.2",
15
+ "react": "^19",
16
+ "react-dom": "^19",
17
+ "react-router": "^7"
36
18
  },
37
19
  "devDependencies": {
38
20
  "@eslint/js": "^9.17.0",
39
- "@types/react": "^18",
40
- "@types/react-dom": "^18",
21
+ "@types/react": "^19",
22
+ "@types/react-dom": "^19",
41
23
  "@vitejs/plugin-react": "^4.3.4",
42
24
  "eslint": "^9.17.0",
43
25
  "eslint-plugin-react": "^7.37.2",
44
26
  "eslint-plugin-react-hooks": "^5.0.0",
45
27
  "eslint-plugin-react-refresh": "^0.4.16",
46
28
  "globals": "^15.14.0",
29
+ "typescript": "^5.9.3",
47
30
  "vite": "^6.3.5",
48
- "vite-plugin-node-polyfills": "^0.24.0"
31
+ "vite-plugin-node-polyfills": "0.23.0"
49
32
  }
50
33
  }
@@ -0,0 +1,22 @@
1
+ import { BrowserRouter, Routes, Route } from "react-router";
2
+
3
+ import { Navigation } from "@/components/navigation";
4
+ import Home from "@/pages/home";
5
+ import HelloNear from "@/pages/hello_near";
6
+ import { NearProvider } from 'near-connect-hooks';
7
+
8
+ function App () {
9
+ return (
10
+ <NearProvider>
11
+ <BrowserRouter>
12
+ <Navigation />
13
+ <Routes>
14
+ <Route path="/" element={<Home />} />
15
+ <Route path="/hello-near" element={<HelloNear />} />
16
+ </Routes>
17
+ </BrowserRouter>
18
+ </NearProvider>
19
+ );
20
+ };
21
+
22
+ export default App;
@@ -1,5 +1,5 @@
1
- import styles from '@/styles/app.module.css';
2
- import { Link } from 'react-router';
1
+ import styles from '@/styles/app.module.css'
2
+ import { Link } from 'react-router'
3
3
 
4
4
  export const Cards = () => {
5
5
  return (
@@ -23,5 +23,5 @@ export const Cards = () => {
23
23
  <p>Discover how simple it is to interact with a Near smart contract.</p>
24
24
  </Link>
25
25
  </div>
26
- );
27
- };
26
+ )
27
+ }
@@ -0,0 +1,43 @@
1
+ import { Link } from 'react-router'
2
+ import NearLogo from '@/assets/near-logo.svg';
3
+ import styles from '@/styles/app.module.css';
4
+ import { useNearWallet } from 'near-connect-hooks';
5
+
6
+ export const Navigation = () => {
7
+ const { signedAccountId, loading, signIn, signOut } = useNearWallet();
8
+
9
+ const handleAction = () => {
10
+ if (signedAccountId) {
11
+ signOut();
12
+ } else {
13
+ signIn();
14
+ }
15
+ };
16
+
17
+ const label = loading
18
+ ? "Loading..."
19
+ : signedAccountId
20
+ ? `Logout ${signedAccountId}`
21
+ : "Login";
22
+
23
+ return (
24
+ <nav className="navbar navbar-expand-lg">
25
+ <div className="container-fluid">
26
+ <Link to="/">
27
+ <img
28
+ src={NearLogo}
29
+ alt="NEAR"
30
+ width={30}
31
+ height={24}
32
+ className={styles.logo}
33
+ />
34
+ </Link>
35
+ <div className="navbar-nav pt-1">
36
+ <button className="btn btn-secondary" onClick={handleAction}>
37
+ {label}
38
+ </button>
39
+ </div>
40
+ </div>
41
+ </nav>
42
+ );
43
+ };
@@ -4,4 +4,4 @@ const contractPerNetwork = {
4
4
  };
5
5
 
6
6
  export const NetworkId = 'testnet';
7
- export const HelloNearContract = contractPerNetwork[NetworkId];
7
+ export const HelloNearContract = contractPerNetwork[NetworkId];
@@ -0,0 +1,13 @@
1
+ // CSS module declarations
2
+ declare module '*.module.css';
3
+ declare module '*.module.scss';
4
+ declare module '*.module.sass';
5
+
6
+ // Image declarations
7
+ declare module '*.svg';
8
+ declare module '*.png';
9
+ declare module '*.jpg';
10
+ declare module '*.jpeg';
11
+ declare module '*.gif';
12
+ declare module '*.webp';
13
+
@@ -0,0 +1,14 @@
1
+ import { StrictMode } from 'react';
2
+ import { createRoot } from 'react-dom/client';
3
+ import '@/styles/globals.css';
4
+ import App from '@/App';
5
+
6
+ const rootElement = document.getElementById('root');
7
+
8
+ if (rootElement) {
9
+ createRoot(rootElement).render(
10
+ <StrictMode>
11
+ <App />
12
+ </StrictMode>
13
+ );
14
+ }
@@ -0,0 +1,95 @@
1
+ import { useEffect, useState, ChangeEvent } from 'react';
2
+ import { Cards } from '@/components/cards';
3
+ import styles from '@/styles/app.module.css';
4
+
5
+ import { HelloNearContract } from '@/config';
6
+ import { useNearWallet } from 'near-connect-hooks';
7
+
8
+ interface useNearHook {
9
+ signedAccountId: string | null;
10
+ viewFunction: (params: { contractId: string; method: string; args?: Record<string, unknown> }) => Promise<any>;
11
+ callFunction: (params: { contractId: string; method: string; args?: Record<string, unknown> }) => Promise<any>;
12
+ }
13
+
14
+ // Contract constant
15
+ const CONTRACT = HelloNearContract as string;
16
+
17
+ export default function HelloNear() {
18
+ const { signedAccountId, viewFunction, callFunction } = useNearWallet() as useNearHook;
19
+
20
+ const [greeting, setGreeting] = useState<string>('loading...');
21
+ const [newGreeting, setNewGreeting] = useState<string>('loading...');
22
+ const [loggedIn, setLoggedIn] = useState<boolean>(false);
23
+ const [showSpinner, setShowSpinner] = useState<boolean>(false);
24
+
25
+ useEffect(() => {
26
+ viewFunction({ contractId: CONTRACT, method: 'get_greeting' })
27
+ .then((greeting) => setGreeting(greeting))
28
+ .catch(console.error);
29
+ }, [viewFunction]);
30
+
31
+ useEffect(() => {
32
+ setLoggedIn(!!signedAccountId);
33
+ }, [signedAccountId]);
34
+
35
+ const saveGreeting = async () => {
36
+ try {
37
+ await callFunction({
38
+ contractId: CONTRACT,
39
+ method: 'set_greeting',
40
+ args: { greeting: newGreeting },
41
+ });
42
+ } catch (error) {
43
+ console.error(error);
44
+ const greeting = await viewFunction({ contractId: CONTRACT, method: 'get_greeting' });
45
+ setGreeting(greeting);
46
+ }
47
+
48
+ setShowSpinner(true);
49
+ await new Promise((resolve) => setTimeout(resolve, 300));
50
+ setGreeting(newGreeting);
51
+ setShowSpinner(false);
52
+ };
53
+
54
+ const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
55
+ setNewGreeting(e.target.value);
56
+ };
57
+
58
+ return (
59
+ <main className={styles.main}>
60
+ <div className={styles.description}>
61
+ <p>
62
+ Interacting with the contract: &nbsp;
63
+ <code className={styles.code}>{CONTRACT}</code>
64
+ </p>
65
+ </div>
66
+ <div className={styles.center}>
67
+ <h1 className="w-100">
68
+ The contract says: <code>{greeting}</code>
69
+ </h1>
70
+
71
+ {loggedIn ? (
72
+ <div className="input-group">
73
+ <input
74
+ type="text"
75
+ className="form-control w-20"
76
+ placeholder="Store a new greeting"
77
+ onChange={handleChange}
78
+ />
79
+ <div className="input-group-append">
80
+ <button className="btn btn-secondary" onClick={saveGreeting}>
81
+ <span hidden={showSpinner}>Save</span>
82
+ <i className="spinner-border spinner-border-sm" hidden={!showSpinner}></i>
83
+ </button>
84
+ </div>
85
+ </div>
86
+ ) : (
87
+ <div className="w-100 text-end align-text-center">
88
+ <p className="m-0">Please login to change the greeting</p>
89
+ </div>
90
+ )}
91
+ </div>
92
+ <Cards />
93
+ </main>
94
+ );
95
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": ".",
4
+ "paths": {
5
+ "@/*": [
6
+ "./src/*"
7
+ ]
8
+ },
9
+ "jsx": "preserve",
10
+ "strict": true,
11
+ "moduleResolution": "node",
12
+ "skipLibCheck": true,
13
+ "target": "ES2017",
14
+ "lib": [
15
+ "dom",
16
+ "dom.iterable",
17
+ "esnext"
18
+ ],
19
+ "allowJs": true,
20
+ "noEmit": true,
21
+ "incremental": true,
22
+ "module": "esnext",
23
+ "esModuleInterop": true,
24
+ "resolveJsonModule": true,
25
+ "isolatedModules": true
26
+ },
27
+ "include": [
28
+ "**/*.ts",
29
+ "**/*.tsx",
30
+ "global.d.ts"
31
+ ],
32
+ "exclude": [
33
+ "node_modules"
34
+ ]
35
+ }
@@ -1 +0,0 @@
1
- 3.13
@@ -1,74 +0,0 @@
1
- # contract-py
2
-
3
- cargo-near-new-project-description
4
-
5
- ## How to Build Locally?
6
-
7
- Install Python and Emscripten:
8
-
9
- ```bash
10
- # Install Python (if not already installed)
11
- # Use your system's package manager or download from https://www.python.org/downloads/
12
-
13
- # Install Emscripten (required for compiling Python contracts to WebAssembly)
14
- # For Linux/macOS:
15
- git clone https://github.com/emscripten-core/emsdk.git
16
- cd emsdk
17
- ./emsdk install latest
18
- ./emsdk activate latest
19
- source ./emsdk_env.sh
20
- # Add to your .bashrc or .zshrc for permanent installation:
21
- # echo 'source "/path/to/emsdk/emsdk_env.sh"' >> ~/.bashrc
22
- cd ..
23
-
24
- # For Windows:
25
- # Download and extract: https://github.com/emscripten-core/emsdk
26
- # Then in Command Prompt:
27
- # cd emsdk
28
- # emsdk install latest
29
- # emsdk activate latest
30
- # emsdk_env.bat
31
-
32
- # Verify installation with:
33
- emcc --version
34
-
35
- # Install uv for Python package management
36
- curl -LsSf https://astral.sh/uv/install.sh | sh
37
-
38
- # Install NEAR CLI-RS to deploy and interact with the contract
39
- curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/near-cli-rs/releases/latest/download/near-cli-rs-installer.sh | sh
40
- ```
41
-
42
- Then run:
43
-
44
- ```bash
45
- uvx nearc greeting_contract.py
46
- ```
47
-
48
- ## How to Test Locally?
49
-
50
- ```bash
51
- uv run pytest
52
- ```
53
-
54
- ## How to Deploy?
55
-
56
- To deploy manually, install [`cargo-near`](https://github.com/near/cargo-near) and run:
57
-
58
- ```bash
59
- # Create a new account
60
- cargo near create-dev-account
61
-
62
- # Deploy the contract on it
63
- cargo near deploy <account-id>
64
- ```
65
- ## Useful Links
66
-
67
- - [cargo-near](https://github.com/near/cargo-near) - NEAR smart contract development toolkit for Rust
68
- - [near CLI](https://near.cli.rs) - Iteract with NEAR blockchain from command line
69
- - [NEAR Python SDK Documentation](https://github.com/r-near/near-sdk-py)
70
- - [NEAR Documentation](https://docs.near.org)
71
- - [NEAR StackOverflow](https://stackoverflow.com/questions/tagged/nearprotocol)
72
- - [NEAR Discord](https://near.chat)
73
- - [NEAR Telegram Developers Community Group](https://t.me/neardev)
74
- - NEAR DevHub: [Telegram](https://t.me/neardevhub), [Twitter](https://twitter.com/neardevhub)
@@ -1,31 +0,0 @@
1
- from near_sdk_py import Contract, view, call, init
2
-
3
- class GreetingContract(Contract):
4
- """
5
- A simple greeting contract that stores and returns a message.
6
- """
7
-
8
- @init
9
- def initialize(self, default_message="Hello, NEAR world!"):
10
- """
11
- Initialize the contract with a default greeting message.
12
- """
13
- self.storage["greeting"] = default_message
14
- return {"success": True}
15
-
16
- @call
17
- def set_greeting(self, message: str):
18
- """
19
- Change the greeting message.
20
- """
21
- self.storage["greeting"] = message
22
- self.log_info(f"Saving greeting: {message}")
23
- return {"success": True}
24
-
25
- @view
26
- def get_greeting(self):
27
- """
28
- Retrieve the current greeting message.
29
- """
30
- return self.storage.get("greeting", "Hello, NEAR world!")
31
-
@@ -1,10 +0,0 @@
1
- [project]
2
- name = "py-near"
3
- version = "0.1.0"
4
- description = "Add your description here"
5
- readme = "README.md"
6
- requires-python = ">=3.13"
7
- dependencies = [
8
- "near-pytest>=0.7.1",
9
- "near-sdk-py>=0.7.3",
10
- ]
@@ -1,53 +0,0 @@
1
- from near_pytest.testing import NearTestCase
2
- import json
3
-
4
- class TestGreetingContract(NearTestCase):
5
- @classmethod
6
- def setup_class(cls):
7
- """Compile and deploy the greeting contract."""
8
- super().setup_class()
9
-
10
- # Compile the contract
11
- wasm_path = cls.compile_contract(
12
- "contract.py",
13
- single_file=True
14
- )
15
-
16
- # Deploy the contract
17
- cls.contract_account = cls.create_account("contract")
18
- cls.instance = cls.deploy_contract(cls.contract_account, wasm_path)
19
-
20
- # Initialize the contract
21
- cls.instance.call_as(
22
- account=cls.contract_account,
23
- method_name="initialize",
24
- args={"default_message": "Initial greeting"},
25
- )
26
-
27
- # Create test user
28
- cls.user = cls.create_account("user")
29
-
30
- # Save state for future resets
31
- cls.save_state()
32
-
33
- def setup_method(self):
34
- """Reset state before each test method."""
35
- self.reset_state()
36
-
37
- def test_greeting(self):
38
- # Set greeting as user
39
- result = self.instance.call_as(
40
- account=self.user,
41
- method_name="set_greeting",
42
- args={"message": "Hello from test!"}
43
- )
44
- result = json.loads(result.text)
45
- assert result["success"] == True
46
-
47
- # Get greeting
48
- greeting = self.instance.call_as(
49
- account=self.user,
50
- method_name="get_greeting"
51
- )
52
- assert greeting.text == "Hello from test!"
53
-