{"id":21715132,"url":"https://github.com/ts-defold/tsd-template-web-monetized","last_synced_at":"2025-04-12T19:22:16.477Z","repository":{"id":37850502,"uuid":"310141592","full_name":"ts-defold/tsd-template-web-monetized","owner":"ts-defold","description":"HTML5 Web Monetization TypeScript Template with @ts-defold","archived":false,"fork":false,"pushed_at":"2025-03-09T20:19:57.000Z","size":294,"stargazers_count":3,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-26T13:38:40.532Z","etag":null,"topics":["defold","defold-game","game-development","lua","ts-defold-template","typescript"],"latest_commit_sha":null,"homepage":"https://ts-defold.dev","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ts-defold.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2020-11-04T23:32:03.000Z","updated_at":"2025-03-09T20:20:02.000Z","dependencies_parsed_at":"2024-02-21T04:31:43.757Z","dependency_job_id":"54c48cc1-7c99-46f9-8945-802ee2454bcb","html_url":"https://github.com/ts-defold/tsd-template-web-monetized","commit_stats":null,"previous_names":[],"tags_count":1,"template":true,"template_full_name":"ts-defold/tsd-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ts-defold%2Ftsd-template-web-monetized","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ts-defold%2Ftsd-template-web-monetized/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ts-defold%2Ftsd-template-web-monetized/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ts-defold%2Ftsd-template-web-monetized/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ts-defold","download_url":"https://codeload.github.com/ts-defold/tsd-template-web-monetized/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248618812,"owners_count":21134299,"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":["defold","defold-game","game-development","lua","ts-defold-template","typescript"],"created_at":"2024-11-26T00:41:19.791Z","updated_at":"2025-04-12T19:22:16.450Z","avatar_url":"https://github.com/ts-defold.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Web Monetization\n\n\u003ca href=\"https://discord.gg/eukcq5m\"\u003e\u003cimg alt=\"Chat with us!\" src=\"https://img.shields.io/discord/766898804896038942.svg?colorB=7581dc\u0026logo=discord\u0026logoColor=white\"\u003e\u003c/a\u003e\n\n[Web Monetization](https://webmonetization.org/) is a JavaScript browser API which allows the creation of a payment stream from the user agent to the website. Web Monetization is being proposed as a W3C standard at the Web Platform Incubator Community Group.\n\n## Web Monetization for Defold\n\nThis repository contains a native extension which integrates the Web Monetization JavaScript API with the [Defold game engine](https://www.defold.com). This allows game developers to detect if a player has an active payment stream or not and offer additional content or perks to paying players.\n\n### Installation\n\n1. Fork this template or use [degit](https://www.npmjs.com/package/degit) to download the template locally\n\n```bash\nnpx degit ts-defold/tsd-template-web-monetized my-web-monetized-game\n# or\ngit clone https://github.com/ts-defold/tsd-template-web-monetized.git my-web-monetized-game\n```\n\n2. Initialize\n\n```bash\ncd my-web-monetized-game\nnpm install\n```\n\n3. Generate\n\n```bash\nnpm run build # Transpile the TypeScript files to lua\n# or\nnpm run dev # Watch for changes and regenerate files on save\n```\n\n4. Code\n\n```\ncode .\n```\n\n5. Open `app/game.project` in Defold\n\n- Start making games with TypesScript!\n\n#### Project dependency\n\nTo use Web Monetization in a Defold project this project has to be added as a [Defold library dependency](http://www.defold.com/manuals/libraries/). Open the **game.project** file and in the [Dependencies field in the Project section](https://defold.com/manuals/project-settings/#dependencies) add:\n\nhttps://github.com/defold/extension-webmonetization/archive/master.zip\n\nOr point to the ZIP file of [a specific release](https://github.com/defold/extension-webmonetization/releases).\n\n#### Add payment pointer\n\nThe Web Monetization JavaScript API also requires a payment pointer to create a payment stream. The payment pointer must be added as a `\u003cmeta\u003e` tag in the `\u003chead\u003e` section of the website. The extension will automatically add the `\u003cmeta\u003e` tag when building or bundling a project but the payment pointer must be added to the **game.project** file. Payment pointers are provided by a number of different [companies offering digital wallets](https://webmonetization.org/) (Web Monetization Wallets). Open the **game.project** file using a text editor and add a new section with the payment pointer:\n\n```ini\n[webmonetization]\npayment_pointer = ADD PAYMENT POINTER HERE\n```\n\n### Usage\n\nWhen the extension and a payment pointer has been added to the **game.project** file it is possible to interact with the Web Monetization API from Defold:\n\n```ts\nif (webmonetization !== undefined) {\n\tconst monetized = webmonetization.is_monetized();\n\n\tif (monetized) {\n\t\tprint('The user has an active payment stream');\n\t}\n\n\twebmonetization.set_listener(function (\n\t\tthis: unknown,\n\t\tevent: webmonetization.Event,\n\t\tdetails?: webmonetization.EventDetails,\n\t) {\n\t\tif (event == webmonetization.EVENT_PENDING) {\n\t\t\tprint('The user is trying to make a first payment');\n\t\t} else if (event == webmonetization.EVENT_START) {\n\t\t\tprint('The user has started paying');\n\t\t} else if (event == webmonetization.EVENT_PROGRESS) {\n\t\t\tprint('The user is still paying');\n\t\t} else if (event == webmonetization.EVENT_STOP) {\n\t\t\tprint('The user has stopped paying');\n\t\t}\n\t\tprint(details?.requestId);\n\t});\n}\n```\n\nThe details table contains additional information about the event. Example:\n\n```js\n{\n  paymentPointer: \"$ilp.uphold.com/QkG86UgXzKq8\",\n  assetScale: 9,\n  amount: \"26009\",\n  requestId: \"a1f728aa-21e0-4376-ae99-0ccb22642956\",\n  assetCode: \"XRP\"\n}\n```\n\n### Awesome\n\nCheckout [Awesome Web Monetization](https://github.com/thomasbnt/awesome-web-monetization) for more tools, packages, tutorials, etc.  \nInstall [Akita](https://github.com/esse-dev/akita) to explore how Web Monetization works.  \nSign-up for [Coil](https://coil.com/) to start sending micro-payments now!\n\n\u003cp align=\"center\" class=\"h4\"\u003e\n  TypeScript :heart: Defold\n\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fts-defold%2Ftsd-template-web-monetized","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fts-defold%2Ftsd-template-web-monetized","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fts-defold%2Ftsd-template-web-monetized/lists"}