BlockCypher Send Transaction - ethereum

I am trying to implement the BlockCypher Ethereum API following the docs here:
https://www.blockcypher.com/dev/ethereum/#transaction-api
I am using the Test Network /beth/test, rather than /eth/main.
I successfully created 2 addresses and called the faucet to fill one address with some 1000000000000000000 wei.
But then I can’t seem to be able to send a valid transaction…
Here are all (test) info:
ADDRESS 1
{
"private": "42eb005cbebd33f55b821864fcdc0755876317345ac9d8ad2bf94d734f78395f",
"public": "04c7238abb2e99c50ef3e4fabe21dbf2701f9dc60de24b40e743e84745984957ba7059a3e0b38c226b3580a95ed0e154fba407d089f5c02f90aa5797ead7fc190e",
"address": "7a9373010ce86d8fcd7dd46588d351cddabe7ce8"
}
ADDRESS 2
{
"private": "4a62456df43b89244d349948008064cfe1279ef3a632823f30b371ac54f879a1",
"public": "046c01b338e3c5224aa70fa302fefa5c9767d0f79aa16327e703d01924e894809460b22ab52974706543682d8e16063fd6cbd302b052762a3be5d7720efc4d2fa9",
"address": "73befec27510c64c303d82191eaf276a94603090"
}
Address 2 contains 1000000000000000000 wei, and I am trying to send 1200000000000000 wei to Address 1.
I use the New Transaction method, I send this:
{"inputs":[{"addresses": ["73befec27510c64c303d82191eaf276a94603090"]}],"outputs":[{"addresses": ["7a9373010ce86d8fcd7dd46588d351cddabe7ce8"], "value": 1200000000000000}]}
And I get this response:
{
"tx": {
"block_height": -1,
"block_index": 0,
"hash": "4e875a673e59f0b2d16123659b3a72a8d818a7cb832c5ed1a4bbf8f5b0a4ee87",
"addresses": [
"73befec27510c64c303d82191eaf276a94603090"
],
"total": 1200000000000000,
"fees": 21000000000000,
"size": 43,
"gas_limit": 21000,
"gas_price": 1000000000,
"received": "2018-05-27T13:51:23.247159854Z",
"ver": 0,
"double_spend": false,
"vin_sz": 1,
"vout_sz": 1,
"inputs": [
{
"sequence": 0,
"addresses": [
"73befec27510c64c303d82191eaf276a94603090"
]
}
],
"outputs": [
{
"value": 1200000000000000,
"addresses": [
"7a9373010ce86d8fcd7dd46588d351cddabe7ce8"
]
}
]
},
"tosign": [
"8b765bd6c2065f612eb00aa55c50759049779cff50151395aefc5a3dafa5cc10"
]
}
Then I use Signer with the ToSign from the New Transaction response, and a Hex-Encoded Private Key of Address 2:
signer 8b765bd6c2065f612eb00aa55c50759049779cff50151395aefc5a3dafa5cc10 34613632343536646634336238393234346433343939343830303830363463666531323739656633613633323832336633306233373161633534663837396131
I get this signature:
30440220644db87755b0a8620e7e52bd64977c79350c0989afd587090be13a8f76efbf3a0220463eb6351c839b086f5874f6a125ec4723fb30eb26a6a831600cb4d3034cd9d3
So then I try the Send Transaction method of BlockCypher, here’s my request:
{
"tx": {
"block_height": -1,
"block_index": 0,
"hash": "4e875a673e59f0b2d16123659b3a72a8d818a7cb832c5ed1a4bbf8f5b0a4ee87",
"addresses": [
"73befec27510c64c303d82191eaf276a94603090"
],
"total": 1200000000000000,
"fees": 21000000000000,
"size": 43,
"gas_limit": 21000,
"gas_price": 1000000000,
"received": "2018-05-27T13:51:23.247159854Z",
"ver": 0,
"double_spend": false,
"vin_sz": 1,
"vout_sz": 1,
"inputs": [
{
"sequence": 0,
"addresses": [
"73befec27510c64c303d82191eaf276a94603090"
]
}
],
"outputs": [
{
"value": 1200000000000000,
"addresses": [
"7a9373010ce86d8fcd7dd46588d351cddabe7ce8"
]
}
]
},
"tosign": [
"8b765bd6c2065f612eb00aa55c50759049779cff50151395aefc5a3dafa5cc10"
],
"pubkeys": ["046c01b338e3c5224aa70fa302fefa5c9767d0f79aa16327e703d01924e894809460b22ab52974706543682d8e16063fd6cbd302b052762a3be5d7720efc4d2fa9"],
"signatures": ["30440220644db87755b0a8620e7e52bd64977c79350c0989afd587090be13a8f76efbf3a0220463eb6351c839b086f5874f6a125ec4723fb30eb26a6a831600cb4d3034cd9d3"]
}
And I get back this error:
"Address 0xF6A14d976c86bDbe050cA9426aD491d750be33B1 computed from signature differs from provided one 73befec27510c64c303d82191eaf276a94603090."
Any idea of what am I doing wrong?
I tried several things already, read a few similar issues online, but still no luck.
I also tried the Raw Transaction method of BlockCypher, and also no luck there..
I am not clear what it means as “raw hex-encoded transaction”, I tried to send the Hex-Encoded input I sent to New Transaction:
{"inputs":[{"addresses": ["73befec27510c64c303d82191eaf276a94603090"]}],"outputs":[{"addresses": ["7a9373010ce86d8fcd7dd46588d351cddabe7ce8"], "value": 1200000000000000}]}
So I sent to https://api.blockcypher.com/v1/beth/test/txs/push?token=[mytoken] this:
{"tx":"22696E70757473223A5B7B22616464726573736573223A205B2237336265666563323735313063363463333033643832313931656166323736613934363033303930225D7D5D2C226F757470757473223A5B7B22616464726573736573223A205B2237613933373330313063653836643866636437646434363538386433353163646461626537636538225D2C202276616C7565223A20313230303030303030303030303030307D5D"}
But I get the error:
“rlp: expected input list for types.TxData”.
Please, any help is very much appreciated!

The private key you're passing to the signer tool is not correct. As Address 2 is the sender in your example, you should be using its private key instead, which is 4a62456df43b89244d349948008064cfe1279ef3a632823f30b371ac54f879a1.

Related

How do I parse this response correctly in post man?

I have tried using the below in postman to parse am array response (further below). for some reason I dont just get the id value. and no mater what array position I enter, I get a type error of
cannot read properties of undefined (reading '0')
postman script
const response = pm.response.json();
console.log(pm.globals.get("alarm1Id", response.result.alarms[0].id));
get request response:
{
"status": "success",
"result": {
"alarms": [
{
"id": "C6707LJmR1yTzjYrfoBTxw",
"name": "Test Alarm1",
"state": "PURGED",
"isAssignedToCurrentUser": false,
"timeOfLastStateChange": "2023-01-20T01:04:38.917Z",
"type": "NORMAL",
"associatedCameras": [
"4xIx1DMwMLSwMDU2sTA2NdNLTsw1MBASmCLZ_fximWvi_v08agen8bMBAA"
],
"priority": 0,
"isNoteRequired": false,
"missedTriggers": 0,
"timeOfMostRecentAcknowledgement": "2023-01-20T01:02:09.670Z",
"timeOfMostRecentActivation": "2023-01-20T01:02:02.346Z",
"timeOfMostRecentPurge": "2023-01-20T01:04:38.917Z",
"durationOfPreRecording": "PT5S",
"durationOfPostRecording": "PT1M",
"digitalOutputsToActivate": []
},
{
"id": "kNJnCVsdQFWzvOeBshTqeg",
"name": "FR",
"state": "PURGED",
"isAssignedToCurrentUser": false,
"timeOfLastStateChange": "2022-12-01T23:26:41.482Z",
"type": "NORMAL",
"associatedCameras": [
"49Ix0UsyNU4ySEpN002yTDbSNTFONNW1NLEw001LTkw0NjI2ME-0sNBLTsw1MBASmCLZ_fximWvi_v08agen8bMBAA"
],
"priority": 0,
"isNoteRequired": false,
"missedTriggers": 0,
"timeOfMostRecentAcknowledgement": "2022-07-07T18:21:28.981Z",
"timeOfMostRecentActivation": "2022-07-06T17:17:09.751Z",
"timeOfMostRecentPurge": "2022-12-01T23:26:41.482Z",
"durationOfPreRecording": "PT5S",
"durationOfPostRecording": "PT1M",
"digitalOutputsToActivate": []
}
]
}
}
I have tried different list positions . I'm thinking I just don't fully understand that data structure on the response.
response = JSON.parse(responseBody)
alarm1Id = response.result.alarms[0].id
I did some digging, I was able to extract id data with the script above

Not able to retrieve value in JSON response

I am working on API response validation. I am trying to get the value of the particular field in the API response for validation.
This is my API response.
{
"currentdatetime": "11",
"syncinterval_seconds": 4,
"public_keys": [
{
"system": "aa",
"pubkey": "aa"
}
],
"users": [
{
"username": "user",
"user_id": "user",
"realname": "user_10",
"emailaddress": "test#gmail.com",
"accountenabled": false,
"mustchangepassword": false,
"passwordhash": "$E6gi",
"accesslevel": [
"WORKER"
],
"expiration": "2022-11-02T16:21:52",
"site_specific": false,
"symkey": "aaaa",
"privatekey": "aaa"
},
]
}
I am trying to get username /user id from users through robot code.Like this
${response}= GET ${Base_URL}/v1/sync/users ${data} headers=${header}
${origin}= Get Json Value From String ${response.content} users
${lines} = Set Variable ${origin.content['users']['username']}
It is throwing a "type" error.
Any help will be much appreciated.

How to return result that belongs to user and restrict other data being sent in the result in FeathersJS?

I am new to feathersjs and I've breaking my head on how to restrict users from viewing other's data. For instance from postman when you do find/get(id) http://localhost/users you see list of all the users that are currently registered. However I would only like to return the current users data.
From:
{
"total": 2,
"limit": 10,
"skip": 0,
"data": [
{
"id": 1,
"email": "test#feathersjs.com",
"auth0Id": null,
"createdAt": "2020-02-01T23:16:30.833Z",
"updatedAt": "2020-02-01T23:16:30.833Z"
},
{
"id": 2,
"email": "test1#feathersjs.com",
"auth0Id": null,
"createdAt": "2020-02-01T23:31:50.904Z",
"updatedAt": "2020-02-01T23:31:50.904Z"
}
]
}
To:
{
"total": 1,
"limit": 10,
"skip": 0,
"data": [
{
"id": 1,
"email": "test#feathersjs.com",
"auth0Id": null,
"createdAt": "2020-02-01T23:16:30.833Z",
"updatedAt": "2020-02-01T23:16:30.833Z"
},
]
}
How do I filter result in the after hook function? Can someone please explain.
Answer:
Missed a basic step. All the find(), update() etc return result based on parent class. By Customizing find() method in your own class and using Sequlize.findOne({}) you can return the result you desire.
Damn! I was stupid to not read the docs fully.

How to decode Logs and get back Events with web3?

I have this transaction that emits 2 different events from 2 different contracts. Let's say I have the ABI files for both contracts, how can I parse the events out of the logs field?
For example, here is such transaction that emitted 2 events https://rinkeby.etherscan.io/tx/0xc6525195135a868897bd4c74ea0f6285b98492103be4df6fc5ea43f83b96b8eb#eventlog
And this is the respond of getTransactionReceipt RPC call, how can I parse the event names and their params out of the logs field?
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"blockHash": "0x3da27197fe084a82d76273b40c32e231d2662b229337795a43fde9f8d73b4d2c",
"blockNumber": "0x39a62b",
"contractAddress": null,
"cumulativeGasUsed": "0x48ad9",
"from": "0x20b53b91da0a2d9afdd442b2bb433a40ab7f9613",
"gasUsed": "0x9e36",
"logs": [
{
"address": "0x5328276603d169165d0f71ca67ccc89c45027df3",
"blockHash": "0x3da27197fe084a82d76273b40c32e231d2662b229337795a43fde9f8d73b4d2c",
"blockNumber": "0x39a62b",
"data": "0x000000000000000000000000f63843b0b7fc5097bc1f92658379617513cce546000000000000000000000000ff0e3299e55efd859176d582fc805481e83449150000000000000000000000000000000000000000000000000000000000002245",
"logIndex": "0x1",
"removed": false,
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
],
"transactionHash": "0x5442a15c593b3fcf3069ad7f6a41d8805a66a49ed407d872e46ea95b1c9f6054",
"transactionIndex": "0x3"
},
{
"address": "0x7387e0b25165e9a621f624e47b3362a937892c7b",
"blockHash": "0x3da27197fe084a82d76273b40c32e231d2662b229337795a43fde9f8d73b4d2c",
"blockNumber": "0x39a62b",
"data": "0x0000000000000000000000000000000000000000000000000000000000002245000000000000000000000000ff0e3299e55efd859176d582fc805481e8344915000000000000000000000000f63843b0b7fc5097bc1f92658379617513cce546000000000000000000000000000000000000000000000000016345785d8a0000000000000000000000000000000000000000000000000000000ffcb9e57d4000",
"logIndex": "0x2",
"removed": false,
"topics": [
"0x9accbcf984c4cd67a675ee4d38143974e1fa62aa95da283bd4ca645e408ec283"
],
"transactionHash": "0x5442a15c593b3fcf3069ad7f6a41d8805a66a49ed407d872e46ea95b1c9f6054",
"transactionIndex": "0x3"
}
],
"logsBloom": "0x20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000048000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000010000000000000000000000000000000000000000000000004000000000000000000080000008000000000000000000000000000000000000000400000000000000000000000000002000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"status": "0x1",
"to": "0x7387e0b25165e9a621f624e47b3362a937892c7b",
"transactionHash": "0x5442a15c593b3fcf3069ad7f6a41d8805a66a49ed407d872e46ea95b1c9f6054",
"transactionIndex": "0x3"
}
}

Backbone.js Collections

I am working with backbone.js. I am trying to send a request to restful service i am getting the resultset as json object as shown
{
"Msgs": [
"Alert",
"Not"
],
"MessageStatus": [
"Active",
"Inactive"
],
"date": {
"From": "2013-04-25",
"To": "2013-06-25"
},
"Mlist": {
"Status": "PND",
"Role": "Admin,User",
"To": "2013-06-24",
"Id": 6,
"Datecreated": "2013-06-24",
"Title": "Title5",
"From": "2013-06-20"
}
}.
I am putting the json object extracting and setting it to collection but I am not able to get particular model from the collection with specific id.
If you want to make your model can be identified with id. You have to set the id in the attributes hash:
{
"id": 1001,
"Msgs": [
"Alert",
"Not"
],
"MessageStatus": [
"Active",
"Inactive"
],
"date": {
"From": "2013-04-25",
"To": "2013-06-25"
},
"Mlist": {
"Status": "PND",
"Role": "Admin,User",
"To": "2013-06-24",
"Id": 6,
"Datecreated": "2013-06-24",
"Title": "Title5",
"From": "2013-06-20"
}
}
Then using backbone collection "findWhere" method to get the specific id model.
//assume msgCollection is which you put the models
var model = msgCollection.findWhere({id: 1001});
Hope this is helpful for you.
I think you need to set your model and parse your input data. Checkout http://backbonejs.org/#Collection-model, http://backbonejs.org/#Model-parse and http://backbonejs.org/#Collection-parse.