Create Bitcoin SV transaction with moneybutton/bsv js library - javascript

I want to create a raw transaction using the BSV JavaScript library from MoneyButton (https://github.com/moneybutton/bsv/)
When creating a bitcoin Satoshi Vision (BSV) transaction I always get an error.
'node_modules/bsv/lib/encoding/base58check.js:58 if (csum.toString('hex') !== hash4.toString('hex')) { throw new Error('Checksum mismatch') }'
I have also tried to generate the transaction using the JavaScript BitbossIO/keyring library and I was also not able to generate a raw transaction.
I don't know which part I'm getting wrong.
const bsv = require('bsv');
var privateKey = new bsv.PrivateKey.fromWIF('pL3yyzZEc96qU8PUyAtk3TBzyosTVGhA1eMWc6icZzS2ZKTnHGuAh');
var utxo = new bsv.UnspentOutput({
"txId" : "600fee0e6eca8eb19c40f5bfae5871446e617d44c39a3ad44782c571dbf59650",
"outputIndex" : 1,
"address" : "12cyVmfJVwkBA4MUSUDarUL2jXiM98JEoe",
"script" : "76a91411c5d84f5eca47921b0b92042de543f209c301a188ac",
"satoshis" : 6691
});
var transaction = new bsv.Transaction()
console.log(transaction)
.from(utxo)
.to('1PM2zxJArgHFxqYkrFqN7aKQV8nfnEGA56', 5000)
.change('1PM2zxJArgHFxqYkrFqN7aKQV8nfnEGA56')
.sign(privateKey);
console.log(transaction.toString());´
I wish I could generate a transaction. Also, please find above the private key to the transaction. You may use the 10cents, but please help me with the transaction. ;)

I believe the key you're using is incorrect, as that's the line that's causing the error because the format is incorrect.
Make sure you're using the correct WIF key.

It's a while ago. Found it when I was searching for building transactions.
Yes, the key is incorrect. I have figured out which is the correct key, and processed the transaction.
Here is the code with the correct key:
"use strict";
const bsv = require("bsv");
//const privateKey = new bsv.PrivateKey.fromWIF('pL3yyzZEc96qU8PUyAtk3TBzyosTVGhA1eMWc6icZzS2ZKTnHGuAh');
const privateKey = bsv.PrivateKey.fromWIF('L3yyzZEc96qU8PUyAtk3TBzyosTVGhA1eMWc6icZzS2ZKTnHGuAh');
const utxo = new bsv.Transaction.UnspentOutput({
"txId" : "600fee0e6eca8eb19c40f5bfae5871446e617d44c39a3ad44782c571dbf59650",
"outputIndex" : 1,
"address" : "12cyVmfJVwkBA4MUSUDarUL2jXiM98JEoe",
"script" : "76a91411c5d84f5eca47921b0b92042de543f209c301a188ac",
"satoshis" : 6691
});
const transaction = new bsv.Transaction()
.from(utxo)
.to('1PM2zxJArgHFxqYkrFqN7aKQV8nfnEGA56', 5000)
.change('1PM2zxJArgHFxqYkrFqN7aKQV8nfnEGA56')
.sign(privateKey);
console.log(transaction.toString());

Related

How to return or get the timestamp from google form

please dont mind my ignorance. Currently I am a "Make your office life easier DIYer" and I am trying to build a pdf generator using GoogleForms, whereby, I had already successfully ran a script and produced a pdf file from it.
By using GoogleForms, and the answers to the questions are used to fill up a GoogleDoc template where it automatically changes/replaces the specified values in it. However, the dilemma I am having now is how to capture the 'Timestamp' created after submitting the form.
This was the code I am using:
function onFormSubmit(e) {
const info = e.namedValues;
createPDF(info)
}
function createPDF(info){
const pdfFolder = DriveApp.getFolderById("19Mbse07Dh03SXhCMDCuUHwP1oNqfhul_");
const tempFolder = DriveApp.getFolderById("1ye9x0l_izDGku91g4ekxDMH8JDIyxdB1");
const tempDoc = DriveApp.getFileById("1p2nCjS4z_4MEGSud833DBRf9Lcby0zPWT_k3SjLiMoo");
const newTempFile = tempDoc.makeCopy(tempFolder)
const openDoc = DocumentApp.openById(newTempFile.getId());
const body = openDoc.getBody();
body.replaceText("{q3}", info['Timestamp'][0]);
body.replaceText("{q1}", info['1. Description'][0]);
body.replaceText("{q2}", info['2. Description'][0]);
openDoc.saveAndClose();
const blobPDF = newTempFile.getAs(MimeType.PDF);
const pdfFile = pdfFolder.createFile(blobPDF).setName("My PDF")
}
The problem I have now is how to get the 'Timestamp' created after submitting a form.
The form successfully captures the "1. Description' and "2. Description" and changes the form in GoogleDoc template which I used to create the pdfFile.
I had followed the documentation under the "Form Submit", particularly namedValues to try to return the 'Timestamp'
{
'First Name': ['Jane'],
'Timestamp': ['6/7/2015 20:54:13'],
'Last Name': ['Doe']
}
The documentation, mentioned 'Timestamp', however I cannot extract it.
Can anybody help me out on this? I am certain that I am missing something.
To extract the timestamp use e.namedValues["Timestamp"][0], i.e.
var timestamp = e.namedValues["Timestamp"][0];
I suggest you to spend some time learning about data structures in JavaScript (objects, Arrays)
Resources
JavaScript data types and data structures

Suitescript: Can't Get Result From Search

The following is the script that I write for writing back "ship from location" information to Item Fulfillment for a certain customer. But it's not working.
Anyone see a syntax error, know what I might be missing, or what I can test for?
case "2946":
var warehousecode = WH_Code_Lookup(customer , location);
itemfulfillment.setFieldValue('custbody_warehouse_code', warehousecode);// set warehouse code
// Set Ship from location
var columns = [];
columns[0] = new nlobjSearchColumn('address1');
columns[1] = new nlobjSearchColumn('address2');
columns[2] = new nlobjSearchColumn('city');
columns[3] = new nlobjSearchColumn('state');
columns[4] = new nlobjSearchColumn('country');
columns[5] = new nlobjSearchColumn('zip');
var search = nlapiSearchRecord('location', null, new nlobjSearchFilter('internalid', null, 'is', invCheckFlag), columns);
itemfulfillment.setFieldValue('custbodyship_from_address1', search[0].getValue('address1'));
itemfulfillment.setFieldValue('custbodyship_from_address2', search[0].getValue('address2'));
itemfulfillment.setFieldValue('custbodyship_from_city', search[0].getValue('city'));
itemfulfillment.setFieldValue('custbodyship_from_country', search[0].getValue('country'));
itemfulfillment.setFieldValue('custbodyship_from_state', search[0].getValue('state'));
itemfulfillment.setFieldValue('custbodyship_from_postal_code', search[0].getValue('zip'));
if(location == 6){
itemfulfillment.setFieldValue('thirdpartyacctups',edi_customer_search[0].getValue('custrecord_2nd_3rd_pty_ups'));
itemfulfillment.setFieldValue('thirdpartyzipcodeups',edi_customer_search[0].getValue('custrecord_2nd_3rd_pty_ups_zip'));
itemfulfillment.setFieldValue('thirdpartytypeups','BILLTHIRDPARTY');
}
break;
You stated that the code doesn't work. Is there a specific error, as someone asked? Does the search bring back results or is it an issue in the search itself? Did you add any debug code in your script to see if you can pinpoint where the issue may be?

How to get values from a field in Mongo, using its Java Driver (3.5.0)

I'm using MongoDB in javascript, and have been using Mongo's Java Driver. (It's because it is in JAR format and I'm using Mirth Connect). The thing is, I'm trying to use fields from another collection and bring informtation to the new collection. From what I've read, the filter from the Java Driver should return a DBCursor. I'm not good at javascript, and haven't figured out how to get a value from a field, from a query I made already.
I'm using this to make the query:
var uri = new Packages.com.mongodb.MongoClientURI("mongodb://usr:pwd#localhost:27017/admin");
var mongoClient = new Packages.com.mongodb.MongoClient(uri);
var database = mongoClient.getDatabase("mydb");
var collection = database.getCollection("mycollection");
var person = collection.findOne(com.mongodb.client.model.Filters.eq("person.id", id));
For example, I would like to have the name of the person I associated with the ID. Any help of how can I get it, would be very appreciated.
Also the JSON from the collection is something like this:
{"patient" : {
"id": 1234,
"first_name": "Peter",
"last_name": "Parker",
},
"other_stuff": ...
}
Try below code with find one ( find + first ) with dot notation to access first name for patient.
var uri = new Packages.com.mongodb.MongoClientURI("mongodb://usr:pwd#localhost:27017/admin");
var mongoClient = new Packages.com.mongodb.MongoClient(uri);
var database = mongoClient.getDatabase("mydb");
var collection = database.getCollection("mycollection");
var personName = collection.find(com.mongodb.client.model.Filters.eq("person.‌​id", id)).first().get("patient.first_name")

How to get Key / Id of the data written into Firebase?

I have a application which stores employee records, it stores the employees ID, but also needs each employee to have a local ID, I want to use the ID generated by Firebase when we push data onto the db using push() function as the internal ID for each employee. This is required for change management.
My code:
function submit()
{
var dsRef=new Firebase("https://dataretrievaltest-28983.firebaseio.com/EmployeeDB/EInfo");
var name=document.getElementById('Name').value;
var eid=document.getElementById('EID').value;
var email=document.getElementById('Email').value;
dsRef
.push(
{
Name:name,
EID: eid,
Email: email,
}
);
var pushid=dsRef.name;
console.log("name:"+pushid);
console.log(name);
console.log(eid);
console.log(email);
}
Output of the above code:
name:function (){S("Firebase.name() being deprecated. Please use Firebase.key() instead.");D("Firebase.name",0,0,arguments.length);return this.key()}
savekey.html:104 Djoko
savekey.html:105 0143
savekey.html:106 Djoko#dept.com
Have used Key in place of name as name is deprecated but did not get the key, instead it returns a function.
The code with key in place of name
var pushid=dsRef.key;
console.log("name:"+pushid);
Output after change:
name:function (){D("Firebase.key",0,0,arguments.length);return this.path.e()?null:me(this.path)}
savekey.html:104 Caroline
savekey.html:105 0192
savekey.html:106 caroline#dept.com
I need the Keys viz -Kb5... : which is seen in below Json
"EInfo" : {
"-Kb5UunYfq-8zd_Jc2Nd" : {
"EID" : "0134",
"Email" : "Parker#dept.com",
"Name" : "Parker"
},
"-Kb5V9xHhzVix6BNRM78" : {
"EID" : "1024",
"Email" : "sanchez#dept.com",
"Name" : "sanchez"
}
}
The available properties(key/name) don't give the required output. Please let me know how to retrieve the key and if I am missing anything.
Also tried
var pushid=dsRef.child("EInfo").push().key;
console.log("name:"+pushid);
it did not give the desired result.
name:function (){D("Firebase.key",0,0,arguments.length);return this.path.e()?null:me(this.path)}
savekey.html:104 camila
savekey.html:105 0172
savekey.html:106 camila#dept.com
You're using Firebase SDK version 2.x, but are mixing in syntax from version 3.x. For Firebase 2.x, the syntax to get the key is:
var pushid=dsRef.key();
console.log("name:"+pushid);
If you're creating this app now, you should really be using Firebase 3.x SDKs, in which case the syntax would indeed be dsRef.key (without parentheses).
Update
You seem to be looking for the key of the item that you just created with push(). You can get that by assigning the result from push to a variable:
var newRef = dsRef.push({
Name:name,
EID: eid,
Email: email,
});
console.log(newRef.key()); // or newRef.key when using SDK version 3.x

Translate php soap request to javascript

I need to send a soap request to a web service using javascript, i was given this php example code, but i do not want to learn the language yet just just for one piece of code.
$uuid = "xxxx";
$param = array("uuid"=>new SoapVar($uuid,
XSD_STRING,
"string",
"http://www.w3.org/2001/XMLSchema")
);
$key1 = implode("", $wsdatek);
$keys = array('key' => new SoapVar(sha1($key1),
XSD_STRING,
"string", "http://www.w3.org/2001/XMLSchema")
);
$datosws = array("local_cert" => "../cert/www.page.com.pem",
"trace" => true, "exceptions" => true
);
This question is derived from the unsuccessful research made on this one
Did one example think this is what you want? Assume you can work out the rest on your own.
var datosws = [["local_cert","../cert/www.page.com.pem"],["trace",true],["exceptions",true]];
They keys var incase you get confused
var XSD_STRING = ""; //const
var key1 = ""; // sha1 the key
var keys = [["key",key1],XSD_STRING,"string","http://www.w3.org/2001/XMLSchema"];
In case you are using jQuery on top of you javascript, you should try this plugin:
https://github.com/doedje/jquery.soap

Categories

Resources