https://github.com/frol/near-contract-python-proof-of-concept
https://github.com/frol/near-contract-python-proof-of-concept
Last synced: 12 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/frol/near-contract-python-proof-of-concept
- Owner: frol
- License: apache-2.0
- Created: 2024-03-06T22:52:34.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-01-13T15:37:37.000Z (over 1 year ago)
- Last Synced: 2025-04-02T14:51:38.399Z (over 1 year ago)
- Language: Rust
- Size: 44.9 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Proof of Concept of using Python for NEAR Contracts
I used [RustPython](https://rustpython.github.io/) to create this proof of concept, more specifically, [this fork](https://github.com/RustPython/RustPython/pull/4875) that trims away wasm_bindgen which is not supported in NEAR environments since NEAR environment is not a browser environment.
Here is how to compile it:
```sh
cargo build --target wasm32-unknown-unknown --release
```
NEAR mainnet and testnet has a limit of 1.5MB for the [contract size and transaction size](https://github.com/near/nearcore/blob/master/utils/mainnet-res/res/mainnet_genesis.json#L196-L198), but the resulting binary I got is 9.1MB, so I tried to strip it:
```sh
wasm-opt -Oz --strip --vacuum target/wasm32-unknown-unknown/release/pycontract.wasm -o pycontract.wasm
```
I still get 4.3MB Wasm, which is not enough to push it through.
Next steps are:
1. further tweak RustPython to avoid remaining `__wbindgen_*` imports (see WAT output to see that the current contract tries to import those host methods that are not available, so it won't get executed in NEAR)
2. run a localnet (e.g. with near-workspaces) to get it tested to potentially push NEAR Protocol changes to increase the limits.
## License
Licensed under either of
* Apache License, Version 2.0
([LICENSE-APACHE](LICENSE-APACHE) or )
* MIT license
([LICENSE-MIT](LICENSE-MIT) or )
at your option.