{"id":16253114,"url":"https://github.com/vgrichina/web4-min-contract","last_synced_at":"2025-10-06T18:30:33.613Z","repository":{"id":136252847,"uuid":"572338157","full_name":"vgrichina/web4-min-contract","owner":"vgrichina","description":"Minimal useful Web4 contract. Can be used together with web4-deploy to deploy static websites","archived":false,"fork":false,"pushed_at":"2024-10-01T04:32:08.000Z","size":27,"stargazers_count":10,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-06T02:35:02.607Z","etag":null,"topics":["ipfs","nearprotocol","web3","web4","zig"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vgrichina.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-30T03:43:48.000Z","updated_at":"2024-10-01T04:32:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"96e6fbc7-0f76-45cf-b02e-6c0425111304","html_url":"https://github.com/vgrichina/web4-min-contract","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vgrichina%2Fweb4-min-contract","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vgrichina%2Fweb4-min-contract/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vgrichina%2Fweb4-min-contract/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vgrichina%2Fweb4-min-contract/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vgrichina","download_url":"https://codeload.github.com/vgrichina/web4-min-contract/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235538031,"owners_count":19006075,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ipfs","nearprotocol","web3","web4","zig"],"created_at":"2024-10-10T15:16:00.800Z","updated_at":"2025-10-06T18:30:33.608Z","avatar_url":"https://github.com/vgrichina.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# web4-min-contract\n\nMinimal useful [Web4](https://github.com/vgrichina/web4) contract. Can be used together with [web4-deploy](https://github.com/vgrichina/web4-deploy)\nto deploy website tied to your `.near` account, with static content hosted on IPFS.\n\n## Building from source\n\nInstall [Zig](https://ziglang.org/learn/getting-started/#installing-zig). Below command uses [v0.13.0](https://github.com/ziglang/zig/releases/tag/0.13.0).\n\nThen run:\n\n```bash\nzig build --release=small\n```\n\nYou should get `zig-out/bin/web4-min` file.\n\n## Deploying smart contract\n\nInstall [near-cli-rs](https://github.com/near/near-cli-rs) first.\n\nThen run:\n\n```bash\nnear deploy --wasmFile zig-out/bin/web4-min --accountId \u003cyour-account\u003e.near\n```\n\nSee more on [how to deploy NEAR smart contracts](https://docs.near.org/develop/deploy).\n\n## Deploying website\n\nRun [web4-deploy](https://github.com/vgrichina/web4-deploy) using `npx`:\n\n```bash\nnpx web4-deploy path/to/your/website \u003cyour-account\u003e.near\n```\n\n## How it works\n\n`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.\n\nThen you can access your website using `https://\u003cyour-account\u003e.near.page` Web4 gateway.\n\n## Contract Functions\n\n- `web4_get`: Serves static content from IPFS, with SPA support (redirects to index.html)\n- `web4_setStaticUrl`: Updates the IPFS URL for static content\n- `web4_setOwner`: Updates the contract owner account\n\n## SPA Support\nThe contract automatically redirects paths without file extensions to `index.html`, making it suitable for Single Page Applications (SPAs). For example:\n- `/about` -\u003e serves `/index.html`\n- `/style.css` -\u003e serves directly\n\n## Storage\nThe contract uses two storage keys:\n- `web4:staticUrl` - IPFS URL for static content\n- `web4:owner` - Optional owner account that can manage the contract\n\n## Default Content\nWhen no static URL is set, the contract serves content from:\n```ipfs://bafybeidc4lvv4bld66h4rmy2jvgjdrgul5ub5s75vbqrcbjd3jeaqnyd5e```\nThis contains instructions for getting started.\n\n## Access Control\n\nThe contract can be managed by:\n- The contract account itself\n- An owner account (if set via web4_setOwner)\n\n## Memory Management\nThe contract is optimized for NEAR's ephemeral runtime environment:\n- Memory is automatically freed after each contract call\n- No explicit memory management is needed\n- Built with `-O ReleaseSmall` for minimal contract size\n\n## Development\n\nRun tests:\n```bash\nzig build test\n```\n\nNote: The contract is designed for NEAR's ephemeral runtime environment where memory is automatically freed after execution.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvgrichina%2Fweb4-min-contract","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvgrichina%2Fweb4-min-contract","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvgrichina%2Fweb4-min-contract/lists"}