near-contract-python-proof-of-concept

Stars
5

Proof of Concept of using Python for NEAR Contracts

I used RustPython to create this proof of concept, more specifically, this fork 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:

cargo build --target wasm32-unknown-unknown --release

NEAR mainnet and testnet has a limit of 4.1MB for the contract size and transaction size, but the resulting binary I got is 9.1MB, so I tried to strip it:

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.