RangeError: private key length is invalid: secp256k1.sign(msgHash, privateKey); - ethereum

Getting below error while signing the transaction on ethereum network:
E:\Web3\node_modules\ethereumjs-util\dist\index.js:369
var sig = secp256k1.sign(msgHash, privateKey);
^
RangeError: private key length is invalid
at Object.exports.ecsign (E:\Web3\node_modules\ethereumjs-util\dist\index.js:369:23)
at Transaction.sign (E:\Web3\node_modules\ethereumjs-tx\es5\index.js:252:23)
at Object.web3.eth.getTransactionCount [as callback] (E:\Web3\app3.js:264:8)
at sendTxCallback (E:\Web3\node_modules\web3-core-method\src\index.js:484:29)
at E:\Web3\node_modules\web3-core-requestmanager\src\index.js:147:9
And here is the web3 code responsible for this error. I am converting the private key values to 'hex' representation but it still not working out.
const Tx = require('ethereumjs-tx')
const Web3 = require('web3')
const web3 = new Web3('https://ropsten.infura.io/tBIZU6erdu0roIzShVDM')
const account1='0xceAbcE5eE63212e7d4fAf9eB522d2B7b5886bF1F'
const account2='0x5F16088a3dec5c07E02317B403472c9ff5335912'
console.log(process.env.PRIVATE_KEY_1)
const privateKey1 = Buffer.from(process.env.PRIVATE_KEY_1, 'hex')
const privateKey2 = Buffer.from(process.env.PRIVATE_KEY_2, 'hex')
console.log(privateKey1)
console.log(privateKey2)
contractABI = [
{
"constant": true,
"inputs": [],
"name": "name",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_spender",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "approve",
"outputs": [
{
"name": "success",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "totalSupply",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_from",
"type": "address"
},
{
"name": "_to",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "transferFrom",
"outputs": [
{
"name": "success",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "standard",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "symbol",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_to",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [
{
"name": "success",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "address"
},
{
"name": "",
"type": "address"
}
],
"name": "allowance",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"name": "_initialSupply",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "_from",
"type": "address"
},
{
"indexed": true,
"name": "_to",
"type": "address"
},
{
"indexed": false,
"name": "_value",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "_owner",
"type": "address"
},
{
"indexed": true,
"name": "_spender",
"type": "address"
},
{
"indexed": false,
"name": "_value",
"type": "uint256"
}
],
"name": "Approval",
"type": "event"
}
]
const contractAddress = '0x30a8999Cb4c766fD6BA21723679466169710f053'
const contract = new web3.eth.Contract(contractABI, contractAddress)
const data = contract.methods.transfer(account2, 1000).encodeABI()
web3.eth.getTransactionCount(account1, (err, txCount) => {
//Build Tx
const txObject = {
nonce: web3.utils.toHex(txCount),
gasLimit: web3.utils.toHex(800000),
gasPrice: web3.utils.toHex(web3.utils.toWei('10', 'gwei')),
to: contractAddress,
data: data
}
//sign the Tx
const tx = new Tx(txObject)
tx.sign(privateKey1)
const serializedTransaction = tx.serialize()
const raw = '0x' + serializedTransaction.toString('hex')
//Broadcast Tx
web3.eth.sendSignedTransaction(raw, (err, txHash) => {
console.log('err: ',err,'txHash:', txHash)
})
})
I even tried without using the 'hex' conversion of private keys, also I tried removing '0x' from the private key values but nothing is working out.
Can anyone suggest, what can be issue here as I am new to Web3 and trying my level best to understand it.

I know it way to late but for anyone searching this, try :const privateKey = Buffer.from(process.env.PRIVATE_KEY, "hex");
It worked for me ;)

Try sending the private key removing the '0x'
Maybe like this:
process.env.PRIVATE_KEY_1.substr(2);
Hope it helps!

Related

Angular Version 14: Getting 'pokemons' array of a trainer

Good morning!
These days i've been working on a pokemon-based project.
My issue to solve right now is to solve the function located at service which gets the pokemons array of a trainer (function below):
getPokemonsOfATrainer(nombreEntrenador: string){
return this.http.get<Trainer>(`${this.apiUrl1}?fullName=${nombreEntrenador}`).pipe(
map( (entrenador: Trainer) => {
return entrenador.pokemons;
})
);
}
My mocked JSON (example of 1 trainer), it's in the following format:
{
"entrenadores": [
{
"fullName": "Alecs",
"pokemons" : [
{
"name":"Venusaur",
"nature": "Calm",
"attacks": [
{
"name":"Leech Seed",
"type":"Grass",
"style":"Attack"
},
{
"name":"Sleep Powder",
"type":"Grass",
"style":"Support"
},
{
"name":"Grass Knot",
"type":"Grass",
"style":"Attack"
},
{
"name":"Sludge Bomb",
"type":"Poison",
"style":"Attack"
}
]
},
{
"name": "Skarmory",
"nature": "Impish",
"attacks": [
{
"name": "Slash",
"type": "Normal",
"style": "Attack"
},
{
"name": "Spikes",
"type": "Bug",
"style": "Support"
},
{
"name": "Brave Bird",
"type": "Flying",
"style": "Attack"
},
{
"name": "Rock Slide",
"type": "Rock",
"style": "Attack"
}
]
},
{
"name": "Registeel",
"nature": "Careful",
"attacks": [
{
"name": "Focus Blast",
"type": "Fighting",
"style": "Attack"
},
{
"name": "Hyper Beam",
"type": "Normal",
"style": "Attack"
},
{
"name": "Shadow Claw",
"type": "Dark",
"style": "Attack"
},
{
"name": "Rock Smash",
"type": "Rock",
"style": "Attack"
}
]
},
{
"name": "Uxie",
"nature": "Impish",
"attacks": [
{
"name": "Future Sight",
"type": "Psychic",
"style": "Support"
},
{
"name": "Memento",
"type": "Normal",
"style": "Support"
},
{
"name": "Dazzling Gleam",
"type": "Psychic",
"style": "Support"
},
{
"name": "Drain Punch",
"type": "Fighting",
"style": "Attack"
}
]
},
{
"name": "Gallade",
"nature": "Adamant",
"attacks": [
{
"name": "Hypnosis",
"type": "Psychic",
"style": "Support"
},
{
"name": "Night Slash",
"type": "Ghost",
"style": "Attack"
},
{
"name": "Brick Break",
"type": "Fighting",
"style": "Attack"
},
{
"name": "Close Combat",
"type": "fighting",
"style": "Support"
}
]
}
]
}
]
}
Would exist a proper way to get the pokemons of a trainer?
Thanks in advance!
You should use HttpClientTestingModule and follow the standard way how to stub the response of http requests. For example, this one: https://ng-mocks.sudo.eu/guides/http-request
Your test can look like:
describe('suite', () => {
beforeEach(() => TestBed.configureTestingModule({
imports: [HttpClientTestingModule], // <- add
providers: [PokemonService],
}).compileComponents());
it('test', () => {
// getting the service and httpMock
const service = TestBed.inject(PokemonService);
const httpMock = TestBed.inject(HttpTestingController);
// subscribing to the result of the http request
let actual: any;
service.getPokemonsOfATrainer('trainer')
.subscribe(value => actual = value);
// stubbing the http request
const req = httpMock.expectOne('<PUT_HERE_API_URL>?fullName=Alecs');
expect(req.request.method).toEqual('GET');
req.flush(mockedJson.entrenadores);
httpMock.verify();
// asserting that we got what expected
expect(actual).toEqual(mockedJson.entrenadores.pokemons);
});
});

Parsing a list of images from NOTION database to flutter app

I am trying to display Notion content such as texts, dates, booleans and images on flutter app.. For texts, dates, and booleans, everything is working.. but I am stuck at displaying images. Please kindly take a look at my JSON file and my code.. and let me know where I am doing wrong..
JSON file that I got from my Notion database
{
"object": "list",
"results": [
{
"object": "page",
"id": "0f2aad20-225a-4d40-b853-fb5943e01636",
"created_time": "2022-09-01T05:14:00.000Z",
"last_edited_time": "2022-09-03T09:56:00.000Z",
"created_by": {
"object": "user",
"id": "33138aa4-0670-49f9-a118-daaef0698369"
},
"last_edited_by": {
"object": "user",
"id": "33138aa4-0670-49f9-a118-daaef0698369"
},
"cover": null,
"icon": null,
"parent": {
"type": "database_id",
"database_id": "f24cee3c-bd2f-466a-bc5f-a505e83b348f"
},
"archived": false,
"properties": {
"Price Range": {
"id": "BiJQ",
"type": "select",
"select": {
"id": "]erF",
"name": "< 2000 Lakh",
"color": "default"
}
},
"On Market": {
"id": "Bxp%60",
"type": "checkbox",
"checkbox": false
},
"Longitude ": {
"id": "CGYh",
"type": "number",
"number": 96.113146
},
"Asking Price in Lakh": {
"id": "Gv%7D%7D",
"type": "number",
"number": 590
},
"Township": {
"id": "MP%7D%3D",
"type": "select",
"select": {
"id": "qwfy",
"name": "Mingaladon - YGN",
"color": "default"
}
},
"Owner Phone": {
"id": "Mqhp",
"type": "phone_number",
"phone_number": "09448840549"
},
"Images": {
"id": "OLC%3B",
"type": "files",
"files": [
{
"name": "31_AUG-22.jpg",
"type": "file",
"file": {
"url": "https://s3.us-west-2.amazonaws.com/secure.notion-static.com/04b39e7e-c2c4-4ccd-a653-348933fa613e/31_AUG-22.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45EIPT3X45%2F20220903%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20220903T102952Z&X-Amz-Expires=3600&X-Amz-Signature=2db13c256bfd191fc3fbc0941438a4a1c75a8da128b6f69b6e2a63002140327b&X-Amz-SignedHeaders=host&x-id=GetObject",
"expiry_time": "2022-09-03T11:29:52.168Z"
}
},
{
"name": "31_AUG-21.jpg",
"type": "file",
"file": {
"url": "https://s3.us-west-2.amazonaws.com/secure.notion-static.com/06ce697d-af96-4f3e-b26e-bc092cacfdf8/31_AUG-21.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45EIPT3X45%2F20220903%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20220903T102952Z&X-Amz-Expires=3600&X-Amz-Signature=33d5c21d71113008f3fbc4f95bf311515e4d42a3eb1f8c6c10fccc355e4e2d9a&X-Amz-SignedHeaders=host&x-id=GetObject",
"expiry_time": "2022-09-03T11:29:52.209Z"
}
},
{
"name": "31_AUG-23.jpg",
"type": "file",
"file": {
"url": "https://s3.us-west-2.amazonaws.com/secure.notion-static.com/32ec9466-fe8a-4eb9-8c1b-0d0abbe8637b/31_AUG-23.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45EIPT3X45%2F20220903%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20220903T102952Z&X-Amz-Expires=3600&X-Amz-Signature=059545c77b9a2330483d34292d2b7e4503d3e9f7ceac67cd44f63d56d6d8a0f0&X-Amz-SignedHeaders=host&x-id=GetObject",
"expiry_time": "2022-09-03T11:29:52.271Z"
}
}
]
},
"Zone": {
"id": "O_ui",
"type": "select",
"select": {
"id": "bWGg",
"name": "13",
"color": "default"
}
},
"Progress": {
"id": "P%3C%7BM",
"type": "multi_select",
"multi_select": []
},
"Category": {
"id": "PM%5EA",
"type": "select",
"select": {
"id": "kLgI",
"name": "Residential",
"color": "default"
}
},
"Status": {
"id": "R%7B%5Dl",
"type": "select",
"select": {
"id": ":huS",
"name": "For Sale",
"color": "default"
}
},
"Latitude ": {
"id": "TUmm",
"type": "number",
"number": 16.955839
},
"Flooring": {
"id": "U%3FS%5D",
"type": "rich_text",
"rich_text": []
},
"Bathroom": {
"id": "WPEe",
"type": "number",
"number": 1
},
"Price Per Sqft": {
"id": "%5C%3Alg",
"type": "number",
"number": 21000
},
"Address": {
"id": "%5DSz%7C",
"type": "rich_text",
"rich_text": [
{
"type": "text",
"text": {
"content": "Mingalardon, ဝါယာလက် , တောတိုက်ရပ်ကွက်, အမှတ် ၇/၄၉",
"link": null
},
"annotations": {
"bold": false,
"italic": false,
"strikethrough": false,
"underline": false,
"code": false,
"color": "default"
},
"plain_text": "Mingalardon, ဝါယာလက် , တောတိုက်ရပ်ကွက်, အမှတ် ၇/၄၉",
"href": null
}
]
},
"Type": {
"id": "%5E%3E%40F",
"type": "select",
"select": {
"id": "Hb_}",
"name": "House",
"color": "default"
}
},
"State": {
"id": "%5E%7DP%60",
"type": "select",
"select": {
"id": ":fMv",
"name": "YGN",
"color": "default"
}
},
"Year Built": {
"id": "a%5C%5Ce",
"type": "number",
"number": 2014
},
"Data Source": {
"id": "awp%5B",
"type": "select",
"select": {
"id": "Ohch",
"name": "Facebook",
"color": "default"
}
},
"Electricity": {
"id": "bCpc",
"type": "select",
"select": {
"id": "=^]Q",
"name": "1 Single",
"color": "default"
}
},
"Cover Photo": {
"id": "bDDW",
"type": "files",
"files": [
{
"name": "31_AUG-21.jpg",
"type": "file",
"file": {
"url": "https://s3.us-west-2.amazonaws.com/secure.notion-static.com/b2784859-34d3-41c2-a88a-3311d8886804/31_AUG-21.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45EIPT3X45%2F20220903%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20220903T102952Z&X-Amz-Expires=3600&X-Amz-Signature=eb7ab8e22917357922dfa939c250c5106f8e496888b564f17c622d804045f4ff&X-Amz-SignedHeaders=host&x-id=GetObject",
"expiry_time": "2022-09-03T11:29:52.297Z"
}
}
]
},
"Contact": {
"id": "d_%5E%3E",
"type": "relation",
"relation": []
},
"Car Parking": {
"id": "gIBP",
"type": "number",
"number": 2
},
"Water System": {
"id": "gfRJ",
"type": "multi_select",
"multi_select": [
{
"id": "08a52b0a-cbbf-4e7d-8756-c2edb40a8ed9",
"name": "ဂျိုးဖြူရေ",
"color": "gray"
}
]
},
"Sold Date": {
"id": "giQA",
"type": "date",
"date": null
},
"Air Con": {
"id": "mP%5Dd",
"type": "number",
"number": 0
},
"Bedrooms": {
"id": "ptfQ",
"type": "select",
"select": {
"id": "O}`U",
"name": "3",
"color": "default"
}
},
"Owner Direct": {
"id": "py%40O",
"type": "checkbox",
"checkbox": false
},
"Lot Size (Sqft)": {
"id": "t%3AwQ",
"type": "number",
"number": 2795
},
"Type of Ownership": {
"id": "vgED",
"type": "select",
"select": {
"id": "37a4fbaa-955f-48d0-9a4d-4f5a28a8ca9a",
"name": "အရပ်စာချုပ်",
"color": "red"
}
},
"Added Time": {
"id": "x%3Byd",
"type": "last_edited_time",
"last_edited_time": "2022-09-03T09:56:00.000Z"
},
"ခြံအကျယ် (ပေ)": {
"id": "z%3D%3D%40",
"type": "rich_text",
"rich_text": [
{
"type": "text",
"text": {
"content": "43x65",
"link": null
},
"annotations": {
"bold": false,
"italic": false,
"strikethrough": false,
"underline": false,
"code": false,
"color": "default"
},
"plain_text": "43x65",
"href": null
}
]
},
"Structure": {
"id": "%7Cj%5Er",
"type": "select",
"select": {
"id": "ad149505-37a9-4464-8d13-7ff1e34cef3f",
"name": "ပျဉ်ထောင်အိမ်",
"color": "blue"
}
},
"Property Title": {
"id": "%7Cn%3F%3E",
"type": "rich_text",
"rich_text": [
{
"type": "text",
"text": {
"content": "မင်္ဂလာဒုံမြို့နယ်တောတိုက်ရပ်ကွက် ရှိ အိမ်လေးတစ်လုံးရောင်းရန်ရှိ",
"link": null
},
"annotations": {
"bold": false,
"italic": false,
"strikethrough": false,
"underline": false,
"code": false,
"color": "default"
},
"plain_text": "မင်္ဂလာဒုံမြို့နယ်တောတိုက်ရပ်ကွက် ရှိ အိမ်လေးတစ်လုံးရောင်းရန်ရှိ",
"href": null
}
]
},
"360 Photo ": {
"id": "~yOp",
"type": "url",
"url": "https://kuula.co/share/collection/7vSsM?logo=0&info=1&fs=1&vr=0&sd=1&thumbs=1"
},
"Name": {
"id": "title",
"type": "title",
"title": [
{
"type": "text",
"text": {
"content": "YGN-13C-06",
"link": null
},
"annotations": {
"bold": false,
"italic": false,
"strikethrough": false,
"underline": false,
"code": false,
"color": "default"
},
"plain_text": "YGN-13C-06",
"href": null
}
]
}
},
"url": "https://www.notion.so/YGN-13C-06-0f2aad20225a4d40b853fb5943e01636"
},
How I get data from Notion
class NotionAPI {
final http.Client _client;
static const String _baseUrl = 'https://api.notion.com/v1/';
NotionAPI({http.Client? client}) : _client = client ?? http.Client();
void dispose() {
_client.close();
}
Future<List<NotionPropertyModel>> getProperties() async {
try {
final url =
'${_baseUrl}databases/${dotenv.env['NOTION_DATABASE_ID']}/query';
final response = await _client.post(
Uri.parse(url),
headers: {
HttpHeaders.authorizationHeader:
'Bearer ${dotenv.env['NOTION_API_KEY']}',
'Notion-Version': '2022-06-28',
},
);
if (response.statusCode == 200) {
final data = jsonDecode(response.body) as Map<String, dynamic>;
return (data['results'] as List)
.map((e) => NotionPropertyModel.fromMap(e))
.toList()
..sort((a, b) => b.date.compareTo(a.date));
} else {
throw const Failure(message: 'Something went wrong..STW!');
}
} catch (_) {
throw const Failure(message: 'Something went wrong..++++!');
}
}
}
My fromJson method
factory NotionPropertyModel.fromMap(Map<String, dynamic> map) {
final properties = map['properties'] as Map<String, dynamic>;
final dateStr = properties['Date']?['date']?['start'];
return NotionPropertyModel(
pptID: properties['Name']?['title']?[0]?['plain_text'] ?? '?',
date: dateStr != null ? DateTime.parse(dateStr) : DateTime.now(),
dataSource: properties['Data Source']?['select']?['name'] ?? 'Any',
ownerDirect: properties['Owner Direct']?['checkbox'] as bool,
priceInLakh:
(properties['Asking Price in Lakh']?['number'] ?? 0).toDouble(),
coverPhoto: properties['Cover Photo']?['files']?['file']?['url'],
);
}
How I display on the screen
child: Column(
children: [
Image.network(itemData.coverPhoto),
Text(itemData.pptID),
Text(itemData.dataSource),
if (itemData.ownerDirect == true)
const Text(
'Owner Direct',
style: TextStyle(fontSize: 20),
)
],
),
Your cover image is a list of file so change this:
coverPhoto: properties['Cover Photo']?['files']?['file']?['url'],
to
factory NotionPropertyModel.fromMap(Map<String, dynamic> map) {
final properties = map['properties'] as Map<String, dynamic>;
final dateStr = properties['Date']?['date']?['start'];
List coverList = properties['Cover Photo']?['files'] ?? [];
return NotionPropertyModel(
pptID: properties['Name']?['title']?[0]?['plain_text'] ?? '?',
date: dateStr != null ? DateTime.parse(dateStr) : DateTime.now(),
dataSource: properties['Data Source']?['select']?['name'] ?? 'Any',
ownerDirect: properties['Owner Direct']?['checkbox'] as bool,
priceInLakh:
(properties['Asking Price in Lakh']?['number'] ?? 0).toDouble(),
coverPhoto: (coverList != null && coverList.isNotEmpty) ? coverList[0]['file']?['url'] : '',
);
}

How to get the Respiratory Rate from the Google Fit REST API

I am using the Google Fit REST API and want to get the respiratory rate. In the Google Fit app on Android, there is support to add Respiratory Rate. The API that I am using to fetch the data is GET /fitness/v1/users/me/dataSources/{dataSourceId}/datasets/{datasetId} but unable to find the dataSourceId for respiratory rate. Unable to find anything in the documentation at https://developers.google.com/fit/datatypes/health. Usually, the GET /fitness/v1/users/me/dataSources API lists all the data sources but there is nothing for the respiratory rate. Below is the response after granting ALL the Fitness API permissions
{
"dataSource": [
{
"dataQualityStandard": [],
"dataType": {
"field": [
{
"name": "duration",
"format": "integer"
}
],
"name": "com.google.active_minutes"
},
"dataStreamName": "merge_active_minutes",
"application": {
"packageName": "com.google.android.gms"
},
"dataStreamId": "derived:com.google.active_minutes:com.google.android.gms:merge_active_minutes",
"type": "derived"
},
{
"dataQualityStandard": [],
"dataType": {
"field": [
{
"name": "activity",
"format": "integer"
}
],
"name": "com.google.activity.segment"
},
"dataStreamName": "session_activity_segment",
"application": {
"packageName": "com.google.android.apps.fitness"
},
"dataStreamId": "derived:com.google.activity.segment:com.google.android.apps.fitness:session_activity_segment",
"type": "derived"
},
{
"dataQualityStandard": [],
"dataType": {
"field": [
{
"name": "activity",
"format": "integer"
}
],
"name": "com.google.activity.segment"
},
"dataStreamName": "merge_activity_segments",
"application": {
"packageName": "com.google.android.gms"
},
"dataStreamId": "derived:com.google.activity.segment:com.google.android.gms:merge_activity_segments",
"type": "derived"
},
{
"dataQualityStandard": [],
"dataType": {
"field": [
{
"name": "activity",
"format": "integer"
}
],
"name": "com.google.activity.segment"
},
"dataStreamName": "session_activity_segment",
"application": {
"packageName": "com.google.android.gms"
},
"dataStreamId": "derived:com.google.activity.segment:com.google.android.gms:session_activity_segment",
"type": "derived"
},
{
"dataQualityStandard": [],
"dataType": {
"field": [
{
"name": "body_temperature",
"format": "floatPoint"
},
{
"optional": true,
"name": "body_temperature_measurement_location",
"format": "integer"
}
],
"name": "com.google.body.temperature"
},
"dataStreamName": "merged",
"application": {
"packageName": "com.google.android.gms"
},
"dataStreamId": "derived:com.google.body.temperature:com.google.android.gms:merged",
"type": "derived"
},
{
"dataQualityStandard": [],
"dataType": {
"field": [
{
"name": "calories",
"format": "floatPoint"
}
],
"name": "com.google.calories.expended"
},
"dataStreamName": "merge_calories_expended",
"application": {
"packageName": "com.google.android.gms"
},
"dataStreamId": "derived:com.google.calories.expended:com.google.android.gms:merge_calories_expended",
"type": "derived"
},
{
"dataQualityStandard": [],
"dataType": {
"field": [
{
"name": "distance",
"format": "floatPoint"
}
],
"name": "com.google.distance.delta"
},
"dataStreamName": "merge_distance_delta",
"application": {
"packageName": "com.google.android.gms"
},
"dataStreamId": "derived:com.google.distance.delta:com.google.android.gms:merge_distance_delta",
"type": "derived"
},
{
"dataQualityStandard": [],
"dataType": {
"field": [
{
"name": "intensity",
"format": "floatPoint"
}
],
"name": "com.google.heart_minutes"
},
"dataStreamName": "merge_heart_minutes",
"application": {
"packageName": "com.google.android.gms"
},
"dataStreamId": "derived:com.google.heart_minutes:com.google.android.gms:merge_heart_minutes",
"type": "derived"
},
{
"dataQualityStandard": [],
"dataType": {
"field": [
{
"name": "bpm",
"format": "floatPoint"
}
],
"name": "com.google.heart_rate.bpm"
},
"dataStreamName": "merge_heart_rate_bpm",
"application": {
"packageName": "com.google.android.gms"
},
"dataStreamId": "derived:com.google.heart_rate.bpm:com.google.android.gms:merge_heart_rate_bpm",
"type": "derived"
},
{
"dataQualityStandard": [],
"dataType": {
"field": [
{
"name": "bpm",
"format": "floatPoint"
}
],
"name": "com.google.heart_rate.bpm"
},
"dataStreamName": "resting_heart_rate<-merge_heart_rate_bpm",
"application": {
"packageName": "com.google.android.gms"
},
"dataStreamId": "derived:com.google.heart_rate.bpm:com.google.android.gms:resting_heart_rate<-merge_heart_rate_bpm",
"type": "derived"
},
{
"dataQualityStandard": [],
"dataType": {
"field": [
{
"name": "oxygen_saturation",
"format": "floatPoint"
},
{
"name": "supplemental_oxygen_flow_rate",
"format": "floatPoint"
},
{
"optional": true,
"name": "oxygen_therapy_administration_mode",
"format": "integer"
},
{
"optional": true,
"name": "oxygen_saturation_system",
"format": "integer"
},
{
"optional": true,
"name": "oxygen_saturation_measurement_method",
"format": "integer"
}
],
"name": "com.google.oxygen_saturation"
},
"dataStreamName": "merged",
"application": {
"packageName": "com.google.android.gms"
},
"dataStreamId": "derived:com.google.oxygen_saturation:com.google.android.gms:merged",
"type": "derived"
},
{
"dataQualityStandard": [],
"dataType": {
"field": [
{
"name": "sleep_segment_type",
"format": "integer"
}
],
"name": "com.google.sleep.segment"
},
"dataStreamName": "merged",
"application": {
"packageName": "com.google.android.gms"
},
"dataStreamId": "derived:com.google.sleep.segment:com.google.android.gms:merged",
"type": "derived"
},
{
"dataQualityStandard": [],
"dataType": {
"field": [
{
"name": "speed",
"format": "floatPoint"
}
],
"name": "com.google.speed"
},
"dataStreamName": "merge_speed",
"application": {
"packageName": "com.google.android.gms"
},
"dataStreamId": "derived:com.google.speed:com.google.android.gms:merge_speed",
"type": "derived"
},
{
"dataQualityStandard": [],
"dataType": {
"field": [
{
"name": "steps",
"format": "integer"
}
],
"name": "com.google.step_count.delta"
},
"dataStreamName": "estimated_steps",
"application": {
"packageName": "com.google.android.gms"
},
"dataStreamId": "derived:com.google.step_count.delta:com.google.android.gms:estimated_steps",
"type": "derived"
},
{
"dataQualityStandard": [],
"dataType": {
"field": [
{
"name": "steps",
"format": "integer"
}
],
"name": "com.google.step_count.delta"
},
"dataStreamName": "merge_step_deltas",
"application": {
"packageName": "com.google.android.gms"
},
"dataStreamId": "derived:com.google.step_count.delta:com.google.android.gms:merge_step_deltas",
"type": "derived"
},
{
"dataQualityStandard": [],
"dataType": {
"field": [
{
"name": "duration",
"format": "integer"
}
],
"name": "com.google.active_minutes"
},
"dataStreamName": "user_input",
"application": {
"packageName": "com.google.android.apps.fitness"
},
"dataStreamId": "raw:com.google.active_minutes:com.google.android.apps.fitness:user_input",
"type": "raw"
},
{
"dataQualityStandard": [],
"dataType": {
"field": [
{
"name": "activity",
"format": "integer"
}
],
"name": "com.google.activity.segment"
},
"dataStreamName": "user_input",
"application": {
"packageName": "com.google.android.apps.fitness"
},
"dataStreamId": "raw:com.google.activity.segment:com.google.android.apps.fitness:user_input",
"type": "raw"
},
{
"dataQualityStandard": [],
"dataType": {
"field": [
{
"name": "body_temperature",
"format": "floatPoint"
},
{
"optional": true,
"name": "body_temperature_measurement_location",
"format": "integer"
}
],
"name": "com.google.body.temperature"
},
"dataStreamName": "user_input",
"application": {
"packageName": "com.google.android.apps.fitness"
},
"dataStreamId": "raw:com.google.body.temperature:com.google.android.apps.fitness:user_input",
"type": "raw"
},
{
"dataQualityStandard": [],
"dataType": {
"field": [
{
"name": "intensity",
"format": "floatPoint"
}
],
"name": "com.google.heart_minutes"
},
"dataStreamName": "user_input",
"application": {
"packageName": "com.google.android.apps.fitness"
},
"dataStreamId": "raw:com.google.heart_minutes:com.google.android.apps.fitness:user_input",
"type": "raw"
},
{
"dataQualityStandard": [],
"dataType": {
"field": [
{
"name": "bpm",
"format": "floatPoint"
}
],
"name": "com.google.heart_rate.bpm"
},
"dataStreamName": "user_input",
"application": {
"packageName": "com.google.android.apps.fitness"
},
"dataStreamId": "raw:com.google.heart_rate.bpm:com.google.android.apps.fitness:user_input",
"type": "raw"
},
{
"dataQualityStandard": [],
"dataType": {
"field": [
{
"name": "oxygen_saturation",
"format": "floatPoint"
},
{
"name": "supplemental_oxygen_flow_rate",
"format": "floatPoint"
},
{
"optional": true,
"name": "oxygen_therapy_administration_mode",
"format": "integer"
},
{
"optional": true,
"name": "oxygen_saturation_system",
"format": "integer"
},
{
"optional": true,
"name": "oxygen_saturation_measurement_method",
"format": "integer"
}
],
"name": "com.google.oxygen_saturation"
},
"dataStreamName": "user_input",
"application": {
"packageName": "com.google.android.apps.fitness"
},
"dataStreamId": "raw:com.google.oxygen_saturation:com.google.android.apps.fitness:user_input",
"type": "raw"
},
{
"dataQualityStandard": [],
"dataType": {
"field": [
{
"name": "steps",
"format": "integer"
}
],
"name": "com.google.step_count.delta"
},
"dataStreamName": "user_input",
"application": {
"packageName": "com.google.android.apps.fitness"
},
"dataStreamId": "raw:com.google.step_count.delta:com.google.android.apps.fitness:user_input",
"type": "raw"
}
]
}
What data source ID do I need to use to get the respiratory rate?

how to read object by object in nodejs without knowing its structure from a json file

my json file data:
[
{"name":"a","queryname":"Query_1","type":"user","context":"novell","searchsubcontainer":false},
{"name":"aa","queryname":"Query_2","type":"user","context":"novell","searchsubcontainer":true},
{"name":"admin","queryname":"Query_3","type":"user","context":"microfocus","searchsubcontainer":true},
{"name":"*","type":"","context":"novell","searchsubcontainer":true,"queryname":"default"},
{"name":"John","type":"user","context":"novell","searchsubcontainer":true,"auxClasses":[],"advancedFlag":true,"advancedFilter":{"condition":"and","rules":[{"field":"city","operator":"equals","value":"provo"},{"field":"personalTitle","operator":"equals","value":"employee"}]},"queryname":"john"},
{"name":"jack","type":"user","context":"novell","searchsubcontainer":true,"auxClasses":[],"advancedFlag":true,"advancedFilter":{"condition":"and","rules":[{"field":"city","operator":"equals","value":"utah"},{"field":"personalTitle","operator":"equals","value":"manager"}]},"queryname":"jack"},
{"name":"Martin","type":"user","context":"novell","searchsubcontainer":true,"queryname":"martin"},
{"name":"Luke","type":"user","context":"novell","searchsubcontainer":true,"queryname":"luke"},
{"name":"Anay","type":"user","context":"novell","searchsubcontainer":true,"queryname":"Anay"}
]
how do i read these data in nodejs and delete a particular entry in the file using the attribute queryname. is there any way to read object by object from the json array ?
You can use of the operator delete to remove a specific key from a json.
const json = [{
"name": "a",
"queryname": "Query_1",
"type": "user",
"context": "novell",
"searchsubcontainer": false
},
{
"name": "aa",
"queryname": "Query_2",
"type": "user",
"context": "novell",
"searchsubcontainer": true
},
{
"name": "admin",
"queryname": "Query_3",
"type": "user",
"context": "microfocus",
"searchsubcontainer": true
},
{
"name": "*",
"type": "",
"context": "novell",
"searchsubcontainer": true,
"queryname": "default"
},
{
"name": "John",
"type": "user",
"context": "novell",
"searchsubcontainer": true,
"auxClasses": [],
"advancedFlag": true,
"advancedFilter": {
"condition": "and",
"rules": [{
"field": "city",
"operator": "equals",
"value": "provo"
}, {
"field": "personalTitle",
"operator": "equals",
"value": "employee"
}]
},
"queryname": "john"
},
{
"name": "jack",
"type": "user",
"context": "novell",
"searchsubcontainer": true,
"auxClasses": [],
"advancedFlag": true,
"advancedFilter": {
"condition": "and",
"rules": [{
"field": "city",
"operator": "equals",
"value": "utah"
}, {
"field": "personalTitle",
"operator": "equals",
"value": "manager"
}]
},
"queryname": "jack"
},
{
"name": "Martin",
"type": "user",
"context": "novell",
"searchsubcontainer": true,
"queryname": "martin"
},
{
"name": "Luke",
"type": "user",
"context": "novell",
"searchsubcontainer": true,
"queryname": "luke"
},
{
"name": "Anay",
"type": "user",
"context": "novell",
"searchsubcontainer": true,
"queryname": "Anay"
}
];
json.forEach((x) => {
delete x.queryname;
});
console.log(json);

Why my web3.js call ethereum smart contract without error but have no effect?

I had used MIST to deploy an ethereum token contract to my private chain. I can use MIST to interact with this token contract without any problem. I can transfer token between accounts. But when I use my web3.js script to interact with my private chain, it had no error BUT it just couldn't transfer token between accounts. But I can use this web3.js script to get correct balance of the accounts. I am new to ethereum development. Any helps are welcome!
I use the command to start private chain:
geth --identity "ImsaIco" --ipcdisable --nodiscover --rpc --rpcport "9001" --rpccorsdomain "*" --datadir "D:\abiz\blc\dev\icoc\chain" --port "8001" --rpcapi "db,eth,net,web3,personal" --networkid 1001 --mine
To let Mist connect to my private chain I use this command:
"D:\abiz\blc\software\mist\Mist.exe" --rpc "\\.\pipe\geth.ipc"
This is my web3.js script:
var Web3 = require('web3');
var net = require('net');
var web3 = new Web3(new Web3.providers.HttpProvider("http://127.0.0.1:9001"));
var accounts;
// Copied from MIST interface
var heCoinContractAbi = [ { "constant": true, "inputs": [], "name": "name", "outputs": [ { "name": "", "type": "string", "value": "HeCoin" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [ { "name": "_spender", "type": "address" }, { "name": "_value", "type": "uint256" } ], "name": "approve", "outputs": [ { "name": "success", "type": "bool" } ], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [], "name": "totalSupply", "outputs": [ { "name": "", "type": "uint256", "value": "2e+25" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [ { "name": "_from", "type": "address" }, { "name": "_to", "type": "address" }, { "name": "_value", "type": "uint256" } ], "name": "transferFrom", "outputs": [ { "name": "success", "type": "bool" } ], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [], "name": "decimals", "outputs": [ { "name": "", "type": "uint8", "value": "18" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [ { "name": "_value", "type": "uint256" } ], "name": "burn", "outputs": [ { "name": "success", "type": "bool" } ], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [ { "name": "", "type": "address" } ], "name": "balanceOf", "outputs": [ { "name": "", "type": "uint256", "value": "56000000000000000000" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [ { "name": "_from", "type": "address" }, { "name": "_value", "type": "uint256" } ], "name": "burnFrom", "outputs": [ { "name": "success", "type": "bool" } ], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [], "name": "symbol", "outputs": [ { "name": "", "type": "string", "value": "HEC" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [ { "name": "_to", "type": "address" }, { "name": "_value", "type": "uint256" } ], "name": "transfer", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [ { "name": "_spender", "type": "address" }, { "name": "_value", "type": "uint256" }, { "name": "_extraData", "type": "bytes" } ], "name": "approveAndCall", "outputs": [ { "name": "success", "type": "bool" } ], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [ { "name": "", "type": "address" }, { "name": "", "type": "address" } ], "name": "allowance", "outputs": [ { "name": "", "type": "uint256", "value": "0" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "inputs": [ { "name": "initialSupply", "type": "uint256", "index": 0, "typeShort": "uint", "bits": "256", "displayName": "initial Supply", "template": "elements_input_uint", "value": "20000000" }, { "name": "tokenName", "type": "string", "index": 1, "typeShort": "string", "bits": "", "displayName": "token Name", "template": "elements_input_string", "value": "HeCoin" }, { "name": "tokenSymbol", "type": "string", "index": 2, "typeShort": "string", "bits": "", "displayName": "token Symbol", "template": "elements_input_string", "value": "HEC" } ], "payable": false, "stateMutability": "nonpayable", "type": "constructor" }, { "anonymous": false, "inputs": [ { "indexed": true, "name": "from", "type": "address" }, { "indexed": true, "name": "to", "type": "address" }, { "indexed": false, "name": "value", "type": "uint256" } ], "name": "Transfer", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": true, "name": "from", "type": "address" }, { "indexed": false, "name": "value", "type": "uint256" } ], "name": "Burn", "type": "event" } ];
web3.eth.getAccounts(function(error, response){
if(!error) {
accounts = response;
callContractTransfer();
//getContractAccountBalance();
} else {
console.error(error); // there was an error, so let's see it.
}
});
function callContractTransfer() {
var hecoinContract = new web3.eth.Contract(heCoinContractAbi);
hecoinContract.options.address = '0xa960fFc27EF72f2db7AB6c86BaB9549FFcf20717'; // Copied from MIST interface
hecoinContract.methods.transfer(accounts[1], web3.utils.toWei('30', 'ether')).call({from: accounts[0]}, function(error, result) {
console.log('error:' + error + '!');
console.log('result:' + JSON.stringify(result) + '!');
});
}
function getContractAccountBalance() {
var hecoinContract = new web3.eth.Contract(heCoinContractAbi);
hecoinContract.options.address = '0xa960fFc27EF72f2db7AB6c86BaB9549FFcf20717';
hecoinContract.methods.balanceOf(accounts[1]).call({from: accounts[0]}, function(error, result) {
console.log('getContractAccountBalance error:' + error + '!');
console.log(accounts[1] + ':getContractAccountBalance result:' + result + '!');
});
}
According to https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#methods-mymethod-call the method call :
Will call a “constant” method and execute its smart contract method in the EVM without sending any transaction.
You should use the "send" method : https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#methods-mymethod-send with your function "transfer"