Minimal useful Web4 contract. Can be used together with web4-deploy
to deploy website tied to your .near
account, with static content hosted on IPFS.
Install Zig. Below command uses v0.13.0.
Then run:
zig build --release=small
You should get zig-out/bin/web4-min
file.
Install near-cli-rs first.
Then run:
near deploy --wasmFile zig-out/bin/web4-min --accountId <your-account>.near
See more on how to deploy NEAR smart contracts.
Run web4-deploy using npx
:
npx web4-deploy path/to/your/website <your-account>.near
web4-deploy
will upload your website to IPFS and then call web4_setStaticUrl
method in this smart contract to set IPFS hash of your website.
Then you can access your website using https://<your-account>.near.page
Web4 gateway.
web4_get
: Serves static content from IPFS, with SPA support (redirects to index.html)web4_setStaticUrl
: Updates the IPFS URL for static contentweb4_setOwner
: Updates the contract owner account
The contract automatically redirects paths without file extensions to index.html
, making it suitable for Single Page Applications (SPAs). For example:
/about
-> serves/index.html
/style.css
-> serves directly
The contract uses two storage keys:
web4:staticUrl
- IPFS URL for static contentweb4:owner
- Optional owner account that can manage the contract
When no static URL is set, the contract serves content from:
ipfs://bafybeidc4lvv4bld66h4rmy2jvgjdrgul5ub5s75vbqrcbjd3jeaqnyd5e
This contains instructions for getting started.
The contract can be managed by:
- The contract account itself
- An owner account (if set via web4_setOwner)
The contract is optimized for NEAR's ephemeral runtime environment:
- Memory is automatically freed after each contract call
- No explicit memory management is needed
- Built with
-O ReleaseSmall
for minimal contract size
Run tests:
zig build test
Note: The contract is designed for NEAR's ephemeral runtime environment where memory is automatically freed after execution.