simpleledgerinc / grpc-bchrpc-node

A BCHD gRPC client for node.js
11 stars 10 forks source link

Submit/Sign/Send/Broadcast Transaction #1

Closed arsen3d closed 4 years ago

arsen3d commented 4 years ago

Is there an example of how to "Make" a BCH transaction using this library?

jcramer commented 4 years ago

This library is for interacting with bchd full node rpc commands via the grpc interface. There are other libraries for what you're asking.

If you're looking for a place to learn, https://t.me/simpleledger

arsen3d commented 4 years ago

You are right, there are many libraries out there for interfacing with BCH. Many have been deprecated as of today and it's not clear how each building block fits together.

This video by Chris Pacia talk about being able to submit transactions and it does appear to be in api. https://youtu.be/8oKUQPKCyRg?t=1611 image

image

arsen3d commented 4 years ago

@jcramer Why was SubmitTransaction not implemented? It's part of gRPC spec in the proto file. I am having to implement it on my own, but I think it should be part of this lib.

 SubmitTx(txhex: string): Promise<bchrpc.SubmitTransactionResponse> {
        let req = new bchrpc.SubmitTransactionRequest()
        req.setTransaction(txhex);
        return new Promise((resolve, reject) => {
            this.client.submitTransaction(req, (err, data) => {
                if(err!==null) reject(err);
                else resolve(data!);
            })
        })
    }
arsen3d commented 4 years ago

I implemented it outside of the library in case anyone has the same issue. @jcramer , why was it not implemented to start with? It was part of the spec / proto file.

  let req = new bchrpc.SubmitTransactionRequest();
  const fromHexString = hexString => new Uint8Array(hexString.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));
  req.setTransaction(fromHexString(t.toString()))

  grpc.client.submitTransaction(req,(e,r)=>{
    console.log(e,r)
  })
jcramer commented 4 years ago

@arsen3d I only implemented the methods that I needed. I expected someone would fork and add any methods that they wanted to add.