vgrichina/web4-min-contract
Minimal useful Web4 contract. Can be used together with web4-deploy to deploy static websites
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 accountThe 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 directlyThe contract uses two storage keys:
web4:staticUrl
- IPFS URL for static contentweb4:owner
- Optional owner account that can manage the contractWhen 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 is optimized for NEAR's ephemeral runtime environment:
-O ReleaseSmall
for minimal contract sizeRun tests:
zig build test
Note: The contract is designed for NEAR's ephemeral runtime environment where memory is automatically freed after execution.