create-near-app 8.3.0 → 8.4.1

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/messages.js CHANGED
@@ -24,9 +24,21 @@ Please refer to https://github.com/near/create-near-app README to troubleshoot.
24
24
  Notice: some platforms aren't supported (yet).
25
25
  {bold {red ==========================================}}`);
26
26
  exports.setupFailed = setupFailed;
27
+ const mapContractLanguage = (contract) => {
28
+ switch (contract) {
29
+ case 'ts':
30
+ return 'Typescript';
31
+ case 'rs':
32
+ return 'Rust';
33
+ case 'py':
34
+ return 'Python';
35
+ default:
36
+ return '';
37
+ }
38
+ };
27
39
  const successContractToText = (contract) => contract === 'none'
28
40
  ? ''
29
- : (0, chalk_1.default) `a smart contract in {bold ${contract === 'rs' ? 'Rust' : 'Typescript'}}`;
41
+ : (0, chalk_1.default) `a smart contract in {bold ${mapContractLanguage(contract)}}`;
30
42
  exports.successContractToText = successContractToText;
31
43
  const frontendTemplates = {
32
44
  'next-page': 'NextJS (Classic)',
@@ -38,7 +50,7 @@ const successFrontendToText = (frontend) => frontend === 'none'
38
50
  : (0, chalk_1.default) `a web-app using ${frontendTemplates[frontend]}`;
39
51
  exports.successFrontendToText = successFrontendToText;
40
52
  const setupSuccess = (projectName, contract, frontend, install, needsToInstallCargoNear) => (0, exports.show)((0, chalk_1.default) `
41
- Success! Created '${projectName}', ${(0, exports.successContractToText)(contract)}${(0, exports.successFrontendToText)(frontend)}.
53
+ Success! Created '${projectName}', ${(0, exports.successContractToText)(contract)}${(0, exports.successFrontendToText)(frontend)}.
42
54
  ${contract === 'rs'
43
55
  ? (0, chalk_1.default) `🦀 If you are new to Rust please visit {bold {green https://www.rust-lang.org }}\n`
44
56
  : ''}
@@ -64,6 +76,9 @@ const contractInstructions = (projectName, contract, install, needsToInstallCarg
64
76
  if (contract === 'ts') {
65
77
  message += (0, chalk_1.default) ` {blue npm {bold run build}}\n`;
66
78
  }
79
+ else if (contract === 'py') {
80
+ message += (0, chalk_1.default) ` {blue {bold uvx nearc contract.py --create-venv}}\n`;
81
+ }
67
82
  else {
68
83
  message += (0, chalk_1.default) ` {blue {bold cargo near build}}\n`;
69
84
  }
@@ -71,6 +86,9 @@ const contractInstructions = (projectName, contract, install, needsToInstallCarg
71
86
  if (contract === 'ts') {
72
87
  message += (0, chalk_1.default) ` {blue npm {bold run test}}\n`;
73
88
  }
89
+ else if (contract === 'py') {
90
+ message += (0, chalk_1.default) ` {blue {bold uv run pytest}}\n`;
91
+ }
74
92
  else {
75
93
  message += (0, chalk_1.default) ` {blue {bold cargo near test}}\n`;
76
94
  }
package/dist/types.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.APPS = exports.FRONTENDS = exports.CONTRACTS = void 0;
4
- exports.CONTRACTS = ['ts', 'rs', 'none'];
4
+ exports.CONTRACTS = ['ts', 'rs', 'py', 'none'];
5
5
  exports.FRONTENDS = ['next-app', 'next-page', 'vite-react', 'none'];
6
6
  exports.APPS = ['contract', 'gateway'];
7
7
  //# sourceMappingURL=types.js.map
@@ -57,6 +57,7 @@ const appChoices = [
57
57
  const contractChoices = [
58
58
  { title: 'JS/TS Contract', description: 'A Near contract written in javascript/typescript', value: 'ts' },
59
59
  { title: 'Rust Contract', description: 'A Near contract written in Rust', value: 'rs' },
60
+ { title: 'Python Contract', description: 'A Near contract written in Python', value: 'py' },
60
61
  ];
61
62
  const frontendChoices = [
62
63
  { title: 'NextJs (Classic)', description: 'A web-app built using Next.js Page Router', value: 'next-page' },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-near-app",
3
- "version": "8.3.0",
3
+ "version": "8.4.1",
4
4
  "description": "Quickly scaffold your dApp on NEAR Blockchain",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -0,0 +1 @@
1
+ 3.13
@@ -0,0 +1,74 @@
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)
@@ -0,0 +1,31 @@
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
+
@@ -0,0 +1,10 @@
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
+ ]
@@ -0,0 +1,53 @@
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
+