{"id":20001926,"url":"https://github.com/pooltogether/tightbeam","last_synced_at":"2025-05-04T15:33:38.822Z","repository":{"id":36438028,"uuid":"224510744","full_name":"pooltogether/tightbeam","owner":"pooltogether","description":"Makes talking to Ethereum easy.  Ethers.js bindings for Apollo Client.","archived":false,"fork":false,"pushed_at":"2023-01-05T03:42:19.000Z","size":527,"stargazers_count":18,"open_issues_count":16,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-25T04:03:30.688Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/pooltogether.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}},"created_at":"2019-11-27T20:20:39.000Z","updated_at":"2022-10-01T02:07:47.000Z","dependencies_parsed_at":"2023-01-17T01:28:37.650Z","dependency_job_id":null,"html_url":"https://github.com/pooltogether/tightbeam","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pooltogether%2Ftightbeam","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pooltogether%2Ftightbeam/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pooltogether%2Ftightbeam/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pooltogether%2Ftightbeam/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pooltogether","download_url":"https://codeload.github.com/pooltogether/tightbeam/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252356595,"owners_count":21734983,"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":[],"created_at":"2024-11-13T05:19:08.043Z","updated_at":"2025-05-04T15:33:38.482Z","avatar_url":"https://github.com/pooltogether.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# Tightbeam\n\n[![CircleCI](https://circleci.com/gh/pooltogether/tightbeam.svg?style=svg)](https://circleci.com/gh/pooltogether/tightbeam) [Test Coverage](https://coverage.tightbeam.pooltogether.com)\n\nTightbeam is an extension for [Apollo Client](https://github.com/apollographql/apollo-client) that allows you to communicate with Ethereum smart contracts.  \n\nFeatures:\n\n- Make calls to smart contracts.  Calls are batched using [Multicall](https://github.com/makerdao/multicall) when supported by the network.\n- Get current network and account\n- Get blocks\n- Execute transactions\n\nApollo Client is a powerful framework that allows web applications to communicate with GraphQL servers. By leveraging it's powerful caching and the Multicall smart contract it's possible to build extremely fast Ethereum dApps.\n\n## Tutorial\n\nFor a complete walkthrough of building a dapp and adding a subgraph to it checkout the [ETHDenver workshop](https://github.com/pooltogether/ethdenver-graphql-workshop).  It will guide you through dapp creation and integrating a subgraph.\n\n# Installation\n\nTightbeam is published under the scoped package `@pooltogether/tightbeam`.\n\nWithin a project you can install it:\n\n```\n$ yarn add @pooltogether/tightbeam\n```\n\n## Dependencies\n\n| Tested Dependency | Version |\n| ----------        | ------- |\n| [Ethers.js](https://github.com/ethers-io/ethers.js)                     | 4.x     |\n| [Apollo Client](https://github.com/apollographql/apollo-client)         | 2.6.x   |\n| [Apollo Link State](https://github.com/apollographql/apollo-link-state) | 0.4.x   |\n\n**Note:** The latest version of Apollo Client doesn't handle errors correctly when using client resolvers.  See [issue 4575](https://github.com/apollographql/apollo-client/issues/4575).  Errors will be swallowed.\n\nInstead, we recommended that you stick with Apollo Link State until the client has been updated.\n\n# Setup\n\nThe simplest way to get started is to attach the Tightbeam resolvers to ApolloClient:\n\n```javascript\n\nimport { Tightbeam } from 'tightbeam'\n\nimport { withClientState } from 'apollo-link-state'\nimport { InMemoryCache } from 'apollo-cache-inmemory'\nimport { createHttpLink } from 'apollo-link-http'\n\nconst tb = new Tightbeam()\n\nconst cache = new InMemoryCache()\n\n// Ensure that the expected defaults are present\ncache.writeData(tb.defaultCacheData())\n\n// Now attach the Tightbeam resolvers\nconst stateLink = withClientState({\n  cache,\n  resolvers: tb.resolvers()\n})\n\nconst httpLink = createHttpLink({\n  uri: 'https://thegraph.com/yourgraphurl'\n});\n\nclient = new ApolloClient({\n  cache,\n  link: ApolloLink.from([stateLink, httpLink])\n})\n\n```\n\nNote the use of `apollo-link-state`; it's required for multicall batching to work.\n\nThe `defaultCacheData()` function takes one optional argument that is your desired default state.  It will merge the two.\n\nThe `resolvers()` function takes one optional argument of resolvers.  It will merge the Tightbeam resolvers into the passed object.\n\nNow you can talk to Ethereum!\n\n# Usage\n\nLet's query for the current network and account:\n\n```javascript\n\nconst result = await client.query({\n  query: gql`\n    query addressAndNetwork {\n      address @client\n      network @client\n    }\n  `\n})\n\nconsole.log(result)\n/*\n\n{\n  address: \"0x1234...\",\n  network: { \n    name: 'homestead',\n    chainId: 1\n  }\n}\n\n*/\n```\n\nNotice the `@client` directive; this tells Apollo Client that we are querying a client resolver.\n\n# Querying a Contract\n\nTo query a contract, you must first add a contract to the abi mapping:\n\n```javascript\nconst erc20Abi = // ... get the abi from some where\n\n// addContract(name, networkId, address, abi)\ntb.abiMapping.addContract('Dai', 1, '0x6b175474e89094c44da98b954eedeac495271d0f', erc20Abi)\n```\n\nNow you can query functions:\n\n```javascript\nconst result = await client.query({\n  query: gql`\n    query daiQuery {\n      name: call(name: Dai, fn: name) @client\n      totalSupply: call(name: Dai, fn: totalSupply) @client\n    }\n  `\n})\n```\n\nWe can ask for our balance as well:\n\n```javascript\nconst result = await client.query({\n  query: gql`\n    query myBalanceQuery($address: String!) {\n      balance: call(name; Dai, fn: balanceOf, params[$address]) @client\n    }\n  `,\n  variables: {\n    address: '0xc73e0383f3aff3215e6f04b0331d58cecf0ab849'\n  }\n})\n```\n\nThe query defines an `address` variable that can configure the call.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpooltogether%2Ftightbeam","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpooltogether%2Ftightbeam","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpooltogether%2Ftightbeam/lists"}