{"id":18542730,"url":"https://github.com/coinbase/cbpay-js","last_synced_at":"2025-05-14T17:08:35.500Z","repository":{"id":37958488,"uuid":"481019368","full_name":"coinbase/cbpay-js","owner":"coinbase","description":"Coinbase Pay SDK","archived":false,"fork":false,"pushed_at":"2025-03-25T19:50:20.000Z","size":470,"stargazers_count":347,"open_issues_count":93,"forks_count":155,"subscribers_count":59,"default_branch":"main","last_synced_at":"2025-04-13T10:04:25.617Z","etag":null,"topics":[],"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/coinbase.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","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,"zenodo":null}},"created_at":"2022-04-13T00:43:27.000Z","updated_at":"2025-04-09T13:42:47.000Z","dependencies_parsed_at":"2023-11-07T19:27:17.287Z","dependency_job_id":"ab52bb31-0461-4c7e-b2cb-c472fb18d711","html_url":"https://github.com/coinbase/cbpay-js","commit_stats":{"total_commits":72,"total_committers":12,"mean_commits":6.0,"dds":0.6944444444444444,"last_synced_commit":"ef84b787291b25aeebf2714889bef4023800c12f"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coinbase%2Fcbpay-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coinbase%2Fcbpay-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coinbase%2Fcbpay-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coinbase%2Fcbpay-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coinbase","download_url":"https://codeload.github.com/coinbase/cbpay-js/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254190396,"owners_count":22029632,"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-06T20:10:07.726Z","updated_at":"2025-05-14T17:08:35.474Z","avatar_url":"https://github.com/coinbase.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @coinbase/cbpay-js\n\nThe Coinbase Onramp JS SDK contains helper methods to simplify integrating with our fiat onramp. Wallet providers and dapps can leverage Coinbase Onramp and let their users top up their self-custody wallets.\n\n## Documentation\n\nSee the [Coinbase Onramp documentation](https://docs.cdp.coinbase.com/onramp/docs/getting-started/) for instructions on how to onboard to Coinbase Onramp and get started.\n\n## Installation\n\nWith `yarn`:\n\n```shell\nyarn add @coinbase/cbpay-js\n```\n\nWith `npm`:\n\n```shell\nnpm install @coinbase/cbpay-js\n```\n\nThe package is distributed as both ESModules and CommonJS. To use the CommonJS output, the `regenerator-runtime` package will also need to be installed:\n\nWith `yarn`:\n\n```shell\nyarn add regenerator-runtime\n```\n\nWith `npm`:\n\n```shell\nnpm install regenerator-runtime\n```\n\n## Basic example\n\n```jsx\nimport { initOnRamp } from '@coinbase/cbpay-js';\n\nconst options = {\n  appId: '\u003cYour Project ID obtained from Coinbase Developer Platform\u003e',\n  widgetParameters: {\n    // Specify the addresses and which networks they support\n    addresses: { '0x0': ['ethereum','base'], 'bc1': ['bitcoin']},\n    // Filter the available assets on the above networks to just these ones\n    assets: ['ETH','USDC','BTC'],\n  },\n  onSuccess: () =\u003e {\n    console.log('success');\n  },\n  onExit: () =\u003e {\n    console.log('exit');\n  },\n  onEvent: (event) =\u003e {\n    console.log('event', event);\n  },\n  experienceLoggedIn: 'popup',\n  experienceLoggedOut: 'popup',\n  closeOnExit: true,\n  closeOnSuccess: true,\n};\n\n// Initialize the CB Pay instance\nlet onrampInstance;\ninitOnRamp(options, (error, instance) =\u003e {\n  onrampInstance = instance;\n});\n\n// Open the widget when the user clicks a button\nonrampInstance.open();\n```\n\n## React example\n\n```tsx\nimport { CBPayInstanceType, initOnRamp } from \"@coinbase/cbpay-js\";\nimport { useEffect, useState } from \"react\";\n\nexport const PayWithCoinbaseButton: React.FC = () =\u003e {\n  const [onrampInstance, setOnrampInstance] = useState\u003cCBPayInstanceType | null\u003e();\n\n  useEffect(() =\u003e {\n    initOnRamp({\n      appId: '\u003cYour Project ID obtained from Coinbase Developer Platform\u003e',\n      widgetParameters: {\n        // Specify the addresses and which networks they support\n        addresses: { '0x0': ['ethereum','base'], 'bc1': ['bitcoin']},\n        // Filter the available assets on the above networks to just these ones\n        assets: ['ETH','USDC','BTC'],\n      },\n      onSuccess: () =\u003e {\n        console.log('success');\n      },\n      onExit: () =\u003e {\n        console.log('exit');\n      },\n      onEvent: (event) =\u003e {\n        console.log('event', event);\n      },\n      experienceLoggedIn: 'popup',\n      experienceLoggedOut: 'popup',\n      closeOnExit: true,\n      closeOnSuccess: true,\n    }, (_, instance) =\u003e {\n      setOnrampInstance(instance);\n    });\n\n    // When button unmounts destroy the instance\n    return () =\u003e {\n      onrampInstance?.destroy();\n    };\n  }, []);\n\n  const handleClick = () =\u003e {\n    onrampInstance?.open();\n  };\n\n  return \u003cbutton onClick={handleClick} disabled={!onrampInstance}\u003eBuy with Coinbase\u003c/button\u003e;\n};\n```\n\n## React-Native example\n\n### Prerequisites\n\n``` \nyarn add react-native-url-polyfill\n```\n\n```tsx\nimport React, { useMemo } from 'react'\nimport { WebView } from 'react-native-webview'\nimport { generateOnRampURL } from '@coinbase/cbpay-js'\nimport 'react-native-url-polyfill/auto'\n\nconst CoinbaseWebView = ({ currentAmount }) =\u003e {\n  const coinbaseURL = useMemo(() =\u003e {\n    const options = {\n      appId: '\u003cYour Project ID obtained from Coinbase Developer Platform\u003e',\n      // Specify the addresses and which networks they support\n      addresses: { '0x0': ['ethereum','base'], 'bc1': ['bitcoin']},\n      // Filter the available assets on the above networks to just these ones\n      assets: ['ETH','USDC','BTC'],\n      handlingRequestedUrls: true,\n      presetCryptoAmount: currentAmount,\n    }\n\n    return generateOnRampURL(options)\n  }, [currentAmount, destinationAddress])\n\n  const onMessage = useCallback((event) =\u003e {\n    // Check for Success and Error Messages here\n    console.log('onMessage', event.nativeEvent.data)\n    try {\n      const { data } = JSON.parse(event.nativeEvent.data);\n      if (data.eventName === 'request_open_url') {\n        viewUrlInSecondWebview(data.url);\n      }\n    } catch (error) {\n      console.error(error);\n    }\n  }, [])\n\n  return (\n    \u003cWebView source={{ uri: coinbaseURL }} onMessage={onMessage} /\u003e\n  )\n}\n\nexport default CoinbaseWebView\n```\n\n## Aggregator Example\nReview the [Coinbase Developer docs](https://docs.cdp.coinbase.com/onramp/docs/api-aggregating/) for how to produce the parameters for use within an on ramp aggregator.\n\n```tsx\nimport { CBPayInstanceType, initOnRamp } from \"@coinbase/cbpay-js\";\nimport { useEffect, useState } from \"react\";\n\nexport const PayWithCoinbaseButton: React.FC = () =\u003e {\n  const [onrampInstance, setOnrampInstance] = useState\u003cCBPayInstanceType | null\u003e();\n\n  useEffect(() =\u003e {\n    initOnRamp({\n      appId: '\u003cYour Project ID obtained from Coinbase Developer Platform\u003e',\n      widgetParameters: {\n        // Specify the addresses and which networks they support\n        addresses: { '0x0': ['ethereum','base'], 'bc1': ['bitcoin']},\n        // Filter the available assets on the above networks to just these ones\n        assets: ['ETH','USDC','BTC'],\n        // Aggregator params are ignored unless they are all provided.\n        // defaultNetwork is the exception - it's optional.\n        quoteId: '\u003cquote_id from the Buy Quote API\u003e',\n        defaultAsset: 'USDC',\n        defaultNetwork: 'base',\n        defaultPaymentMethod: 'CARD',\n        presetFiatAmount: 20,\n        fiatCurrency: 'USD',\n      },\n      onSuccess: () =\u003e {\n        console.log('success');\n      },\n      onExit: () =\u003e {\n        console.log('exit');\n      },\n      onEvent: (event) =\u003e {\n        console.log('event', event);\n      },\n      experienceLoggedIn: 'popup',\n      experienceLoggedOut: 'popup',\n      closeOnExit: true,\n      closeOnSuccess: true,\n    }, (_, instance) =\u003e {\n      setOnrampInstance(instance);\n    });\n\n    // When button unmounts destroy the instance\n    return () =\u003e {\n      onrampInstance?.destroy();\n    };\n  }, []);\n\n  const handleClick = () =\u003e {\n    onrampInstance?.open();\n  };\n\n  return \u003cbutton onClick={handleClick} disabled={!onrampInstance}\u003eBuy with Coinbase\u003c/button\u003e;\n};\n```\n\n## Contributing\n\nCommit signing is required for contributing to this repo. For details, see the docs on [contributing](./CONTRIBUTING.md) and [commit-signing](./docs/commit-signing.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoinbase%2Fcbpay-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoinbase%2Fcbpay-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoinbase%2Fcbpay-js/lists"}