{"id":26816754,"url":"https://github.com/elliotbraem/web4-api-js","last_synced_at":"2025-04-23T21:11:48.758Z","repository":{"id":277080565,"uuid":"931288825","full_name":"elliotBraem/web4-api-js","owner":"elliotBraem","description":"Simple client library for apps deployed to web4","archived":false,"fork":false,"pushed_at":"2025-02-12T03:11:34.000Z","size":12,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-30T03:34:58.799Z","etag":null,"topics":["near","web4"],"latest_commit_sha":null,"homepage":"","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/elliotBraem.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":"2025-02-12T02:53:53.000Z","updated_at":"2025-02-23T14:18:36.000Z","dependencies_parsed_at":"2025-02-12T03:08:42.802Z","dependency_job_id":"246700c2-9f02-4e27-ba57-ad8498dc8492","html_url":"https://github.com/elliotBraem/web4-api-js","commit_stats":null,"previous_names":["elliotbraem/web4-api-js"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliotBraem%2Fweb4-api-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliotBraem%2Fweb4-api-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliotBraem%2Fweb4-api-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliotBraem%2Fweb4-api-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elliotBraem","download_url":"https://codeload.github.com/elliotBraem/web4-api-js/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250514790,"owners_count":21443210,"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":["near","web4"],"created_at":"2025-03-30T03:35:02.662Z","updated_at":"2025-04-23T21:11:48.616Z","avatar_url":"https://github.com/elliotBraem.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# web4-api-js\n\nSimple client library for authentication, view method calls, and contracts calls for apps deployed to [web4](https://web4.near.page/).\n\n* /web4/login → `login()`\n* /web4/logout → `logout()`\n* `GET` /web4/contract/{contract_id}/{method_name} → `await view()`\n* `POST` /web4/contract/{contract_id}/{method_name} → `await call()`\n\nTo see it in action or deploy your own profile to web4, try out [this example](https://github.com/NEARBuilders/profile).\n\n## Installation\n\n```bash\nnpm install web4-api-js\n# or\nyarn add web4-api-js\n# or\nbun add web4-api-js\n```\n\n\n## Usage\n\n```typescript\nimport { login, logout, isSignedIn, getAccountId, view, call } from 'web4-api-js';\n\n// Authentication\nif (!isSignedIn()) {\n  login({\n    contractId: 'example.near',\n    callbackPath: '/dashboard'\n  });\n}\n\nconst accountId = getAccountId();\nconsole.log('Logged in as:', accountId);\n\n// View method (read-only)\nconst balance = await view(\n  'token.near',\n  'ft_balance_of',\n  { account_id: accountId }\n);\n\n// Call method \nawait call(\n  'token.near',\n  'ft_transfer',\n  { \n    receiver_id: 'bob.near',\n    amount: '1000000000000000000000000'\n  },\n  {\n    deposit: '1', // in yoctoNEAR\n    gas: '100000000000000', // 100 TGas\n    callbackUrl: '/transfer/success'\n  }\n);\n\n// Logout\nlogout();\n```\n\n## API Reference\n\n### Authentication\n\n#### `login(options?: LoginOptions): void`\n\nInitiates the web4 login process by redirecting to global login page\n\n- `options.contractId`: Contract requiring access (optional)\n- `options.callbackPath`: Path to return to after login (optional)\n\n#### `logout(): void`\n\nLogs out the current user and clears web4 session data.\n\n#### `isSignedIn(): boolean`\n\nChecks if a user is currently signed in.\n\n#### `getAccountId(): string | undefined`\n\nGets the currently signed in account ID.\n\n#### `getSessionKey(): string | undefined`\n\nGets the current session's private key.\n\n### Contract Interaction\n\n#### `view\u003cT\u003e(contractId: string, methodName: string, args?: ViewMethodArgs): Promise\u003cT\u003e`\n\nCalls a view method on a web4 contract.\n\n- `contractId`: The contract to call\n- `methodName`: The view method to call\n- `args`: Arguments to pass to the method (optional)\n- Returns: Promise resolving to the method's return value\n\n#### `call\u003cT\u003e(contractId: string, methodName: string, args: ContractCallArgs, options?: ContractCallOptions): Promise\u003cT\u003e`\n\nCalls a method on a web4 contract that can modify state.\n\n- `contractId`: The contract to call\n- `methodName`: The method to call\n- `args`: Arguments to pass to the method\n- `options`: Optional call configuration\n  - `gas`: Gas limit for the transaction\n  - `deposit`: Amount of NEAR to attach to the call\n  - `callbackUrl`: URL to return to after transaction completion\n- Returns: Promise resolving to the execution outcome or redirects for signing\n\n## Contributing\n\nContributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.\n\n\u003cdiv align=\"right\"\u003e\n\u003ca href=\"https://nearbuilders.org\" target=\"_blank\"\u003e\n\u003cimg\n  src=\"https://builders.mypinata.cloud/ipfs/QmWt1Nm47rypXFEamgeuadkvZendaUvAkcgJ3vtYf1rBFj\"\n  alt=\"Near Builders\"\n  height=\"40\"\n/\u003e\n\u003c/a\u003e\n\u003c/div\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felliotbraem%2Fweb4-api-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felliotbraem%2Fweb4-api-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felliotbraem%2Fweb4-api-js/lists"}