GithubHelp home page GithubHelp logo

blockcypher / node-client Goto Github PK

View Code? Open in Web Editor NEW
91.0 91.0 54.0 154 KB

Node.js SDK for the BlockCypher Web services. See http://www.blockcypher.com

License: MIT License

JavaScript 100.00%

node-client's People

Contributors

acityinohio avatar charredgrass avatar dependabot[bot] avatar ejmason avatar matthieu avatar quentinlesceller avatar rllola avatar sogoiii avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-client's Issues

npm version is out of date

The version installed by npm contains old code, though the package.json has the "latest" 0.2, the version number doesn't seem to have been altered after recent changes.

Note that the !error below is a bug that was has already been fixed

> npm install blockcypher@latest
> grep '!error' node_modules/blockcypher/lib/bcypher.js
		if (!error || response.statusCode !== 200) {
		if (!error || (response.statusCode !== 200 && response.statusCode !== 201)) {
		if (!error || response.statusCode !== 204) {
> grep 'version' node_modules/blockcypher/package.json
  "version"       : "0.2.0",

'test' net not working

main and test3 are working.

test is not at time of writing.

I get the following response Endpoint not found. Please check your URL for typos and make sure you're using the correct HTTP method (GET, POST, etc).

Websocket endpoint not working

I am using the Blockcypher API for test bitcoin transactions and I have troubles with the websocket API endpoint.
When sending the regular ping object after creating a new Websocket it works fine:

this.ws.onopen = () => {
      this.ws.send(JSON.stringify({"event": "ping"})) 

but when trying to check the confidence of a transaction like this we get an error

this.ws.onopen = () => {
      this.ws.send(JSON.stringify({event: 'tx-confidence', address:'<bitcoin address as string>', confidence:0.9}))

These are the references I am using are
API reference
Event reference

Is there anything wrong with the datatypes? Any help would be great!

When deleting webhook it attempts to connect to 127.0.0.1

request.del() at

this._del('/hooks/' + id, {}, function (error, body) {

throws this error:

error: {
"errno": "ECONNREFUSED",
"code": "ECONNREFUSED",
"syscall": "connect",
"address": "127.0.0.1",
"port": 80
}

When I replace the request.del() call with this HTTP.call() deletion works:

  const response = HTTP.call("DELETE", urlr,
    {
      query: "token=" + Meteor.settings.BC_TOKEN
    })

  if (response.statusCode === 204) {
    console.log("webhook deleted successfully: ", response.statusCode)
    return true
  } else {
    console.error("error when deleting webhook:", response.statusCode)
    console.log("response.content:", response.content)
  }

Please fix this.

Hooks Endpoint not found

All hooks endpoints are returning the following for me: Endpoint not found. Please check your URL for typos and make sure you're using the correct HTTP method (GET, POST, etc).

// $ TOKEN=<My Token> node index.js
// Endpoint not found. Please check your URL for typos and make sure you're using the correct  HTTP method (GET, POST, etc).
const bcypher = require('blockcypher');
var ecapi = new bcypher('eth','main', process.env.TOKEN);
var webhook = {
	event: "unconfirmed-tx",
	address: "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B",
	url: "https://my.domain.com/callbacks/new-tx"
};
ecapi.createHook(webhook, (t) => console.log(t.response.text));

I've tried generating a new token with no luck.

Let me know if there's anything else that would be helpful to debug. Thanks!

almost 24 hours since transaction.

Hello,

I'm having an issue with my transaction processing.

It's been almost 24 hours and my transaction is still labeled as unspent.

Can someone help me with this?

allow callback as second param on optional parameters.

The method getBlock and others have an optional second parameter. Allow it be a callback function if caller does not want to pass any parameters.

//current
bcapi.getBlock(300000, {}, printResponse); //works
bcapi.getBlock(300000, printResponse); //fails with cb is not a function error

//proposed
bcapi.getBlock(300000, {}, printResponse); //works
bcapi.getBlock(300000, printResponse); //works

getAddrsWallet method does not work when wallet name contains an space

I have created a wallet with name: "test wallet" and it seems the url generated is like this:

https://api.blockcypher.com/v1/bcy/test/wallets/test wallet/addresses

It works using the url encoded version of the wallet name:

https://api.blockcypher.com/v1/bcy/test/wallets/test%20wallet/addresses

Cannot receive wehook event

I create the new-block and confirmed-tx events webhook, which url is generated by ngrok service.
I can access the url by postman and other request tool, but I cannot receive the webhook event.

Am I wrong?

let hook = {
    "event": "confirmed-tx",
    // "url": "http://192.168.137.1:3721/api/test"
    "url": "https://2ea43af3c8bd.ngrok.io/btc/cb"
  }
  bcapi.createHook(hook, (err, data) => {
    if (err !== null) {
      console.error("hook error:", err);
    } else {
      console.log(data)
    }
  })

the webhook is create successfully!
How can I test the event!

Can't create ETH webhook?

So this works fine with BTC but not ETH? I'm trying to create a webhook for ETH address and listen for unconfirmed transactions. With BTC this works as usual and I can see created webhook in https://accounts.blockcypher.com/tokens/hooks/token but when I create the same hook but initiate the blockcypher class with ETH -> it responds me that webhook was created but I can't find it. And it definitely wont work.

const bcApi = new blockCypher('btc', 'main', process.env.BTC_WEBHOOKS_API_TOKEN) - works
const bcApi = new blockCypher('eth', 'main', process.env.BTC_WEBHOOKS_API_TOKEN) - does not work

how to solve this?

Error broadcasting transaction

Hi Blockcypher team,

I got some help earlier on the correct way to format a transaction using the TX skeleton, so I decided to try it again when I got home. I created a new, un-broadcasted, transaction, and I got this error when posting:

{ error: 'Error validating transaction: Transaction 02b1be3be0a6a4f7d8e369cca88520443b3fc0993d3660d4d52e5f383d505650 has an input referencing an unknown transaction: d69adc7c6a355ea4297755350f86c52710a6ebd72a150215c276f3cd4c659d5e.' }

The transaction referenced in the error has 6 confirmations after about an hour:

https://live.blockcypher.com/btc/tx/d69adc7c6a355ea4297755350f86c52710a6ebd72a150215c276f3cd4c659d5e/

Is there a minimum amount of transactions needed for the API to broadcast? Thanks again for helping me earlier!

Here's the raw transaction hash and a gist of the script I'm using:

var axios = require('axios')
axios.post('https://api.blockcypher.com/v1/bcy/test/txs/push',
        {"tx": "01000000015e9d654ccdf376c21502152ad7eba61027c5860f35557729a45e356a7cdc9ad6000000008a47304402201f06d4679b3f835215c338bace1d8b317aeade5346309389b60f4d7753f5a710022033d9e5aafdd4154889b6ab71eb927b8879eeb3dc9c6c2e665e665485f71a4e0b014104f0087a849a6e9ebc5b3fb9090849a22b72c71564e165458a9957150a7dd24639f1f60746cbfa25950ec9bc7064a77141a78c5a309ff7cc0b90050e8a6a1a8ed7ffffffff02da210000000000001976a914fed9eb51a9d13032e4cf2d6a4856fe8bde18b18c88ac0000000000000000546a4c5177723335322d33316472342d4141412d30322d31362d31352d32336f6c2d313030303030303030302d33323132322d333435352d363933352d323334392d323334302d31323333322d30322d31302d313500000000"}
      )
      .then(function (response) {
        console.log(response.data);
      })
      .catch(function (response) {
        console.log(response.data);
      });

Unable to sign transactions on testnet.

Please disregard this as the following comments are more accurate

I have been scouring the internet for a more detailed example on how to actually sign transactions against the BCY testnet but I am not having any luck finding updated information.

Here's the steps I've taken and sorry in advance if I'm doing this completely wrong. I am extremely new to the crypto world.

  1. Installed bcwallet to generate a BCY testnet address bprv/bpub key.
  2. Created a new transaction from newTX() function provided by this library.
  3. Attempting to get a ECPair from the bcwallet private key provided.

I attempt to get the ECPair with the following:

const seed = bip32.fromBase58('bprvTxeXPZq5...');
const firstKeyECPair = bitcoin.ECPair.fromPrivateKey(seed.privateKey);

This is currently failing with "Invalid network version."

Any help at addressing this issue would be GREATLY appreciated.

How do retrieve the json in a variable instead of printing it?

I noticed that in the example code I can only print the json retireved, but I can't manage to retrieve it in a variable. How do I do it? I tried:

var dados;
function printResponse(err, data) {
 if (err !== null) {
   console.log(err);
 } else {
   return data;
 }
}

dados = bcapi.getBlock(1, {}, (dados = printResponse));

console.log(dados);

but "dados" is coming undefined

How do you spend from multisig address?

Hello,

We have problems when we try to make a TX with multisig address

bcapi.newTX({ inputs: [{ addresses: ['35wm5tDfFeEYjeeTZ17Lee16JCi9DkXBBG']}], outputs: [{ addresses: ['1AxY6mEfFn9r2ynScSyb3KRXRS7q6FBGX'], value: 2500 }] }, printResponse)

Output:

{ error: 'Error building input: Cannot use P2SH as input without \'script_type\' set to \'multisig-n-of-m\'' }, { error: 'Not enough funds in 1 inputs to pay for 1 outputs, missing -2500.' }, { error: 'Not enough funds after fees in 0 inputs to pay for 1 outputs, missing -11200.' }, { error: 'Error validating generated transaction: Transaction missing input or output.' } ],

Also, we try with 'script_type': 'multisig-2-of-3' any ideas how to solve it?

How to format a simple Node HTTPS get request against BlockCypher?

Sorry for writing here - this is not directly related to the development of the node-client module - but I've written BlockCypher support 3 times now and haven't got a response and now I'm thinking a better approach may be to reach out to other developers familiar with BlockCypher and Node and this seemed the best place.

Apologies that this is off topic - thanks for your time ๐Ÿ™‡โ€โ™‚๏ธ

I'd like to know how to format a simple GET request against BlockCypher using only the native Node https module.

Example code:

// example options object generated from internal code
options = { hostname: 'api.blockcypher.com',
  path: '/v1/ltc/main/txs/090a0f034b2973f4e13a3a20c1acf86fcc388dff4cca99220ef0e95d176ed0f0',
  port: 443,
  method: 'GET',
  strictSSL: true }

return new Promise( (resolve, reject) => {
    https.request(options, (response) => {
      let data = ''

      console.log('statusCode:', response.status)
      console.log('headers:', response.headers)

      response.setEncoding('utf8')

      response.on('data', (chunk) => {
        data += chunk
      })

      response.on('end', () => {
        resolve(data)
      })
    }).on('error', (err) => {
      reject(err)
    })
  })
}

When I send a request from above I don't get any chunks back and eventually just get a socket hang up after 60 seconds. From everything I've seen in the API documentation (and looking at what request is doing inside the request NPM docs) this simple HTTPS get request should be sending a properly formatted request which matches the request formatted here.

The logic for forming the param string in my code is a little different but as you can see from the example generated object, the path includes the version number for the API which should result in the same request

How to sign transaction on test network?

How can i sign transactions on test network?
the blockcypher documentation about transactions sending is out of date and if i try to solve it malually, has catch an error.
If i try to sign tx by another library (bitcore-explorers, bitcore-lib)
i'm getting the error around deffirence of networks. Somethink like "Address has mismatched network type".
Anybody please show me example that working for now please.

Not able to access from MVC c#, but able to get result from console application.

Hi,

I am trying to consume blockcypher, when i try from console application c#, its fetching the result. but when i use the same in MVC web app. It's not retruning me anything, it's keeping loading all the time. didn't get back again. any idea why i am facing this.

below code i am using:

Blockcypher objmain = new Blockcypher("******************************", Endpoint.BtcTest3);
objmain.GenerateAddress().Wait();

Dogecoin Transaction Issue, Preference always kept at low

Hey, For a few days now, I have been having trouble trying to send dogecoin via the blockcypher API.

var newtx = { inputs: [{addresses: [inputAddr]}], outputs: outputFrmt, preference: 'medium' };

This is how we have set preference, its set to medium, but the transaction is always sent as low miner preference, and hence the transaction does not get accepted to the blockchain.

As can be seen here,
https://live.blockcypher.com/doge/tx/8205508dc4ab75215305ccdd84baa0f1484f377a14eb22de5775370e3c1b7edd/

I have also tried to set Miner Preference to high, but same issue occurs and Miner Preference still stays at low. Due to this the transactions stays for around 12 hours and then doesnt get accepted on the blockchain.

What could be a possible solution to this?

endpoint /oap/$assetId/transfer

using Asset api on main net, getting internal error from transfer endpoint.

Also, can't use tx builder from coinprism with block cypher pushTX endpoint because coinprism signs with high-s. there a legacy mode for pushTX?

request = { from_private: 'xxx',
  to_address: 'akErbek7ic5u2wmSx61RsKQa6NdhDJYJVZD',
  asset_id: 'AXt4jSi1FF4uCtXQ4u1FvXpW5C9sF9zpWM',
  amount: 1 }

bcapi._post('/oap/' + request.asset_id + '/transfer', {}, request, function(error, body) {
etc . . .
}

from_private hidden, the source address is akJcvSJanxtVtqb1vvYA6nGwjidVTreCHyk
https://www.coinprism.info/address/akJcvSJanxtVtqb1vvYA6nGwjidVTreCHyk
error is:

{ error: 'Error broadcasting transfer transaction: Error pushing transaction e1a8b17dcd5a3dcd95e07e9e87f96f9da94e8b738023d65c935d49de711ef3dc: Error validating transaction: Sum of inputs 4600 lesser than outputs 5460..' }

Add to NPM

Will be cool add this repo to npm for easy install in own projects :)

Blueprint file missing

The required file "blockcypher-api-v1.md" to generate the api object is not in the repo and nowhere to be found.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.