Saving a string in python associated with an API

0 votes

I am writing a bit of code which calls an API and grabs the latest Bitcoin Nonce data. I have managed to do this fine, however now I want to be able to save the first nonce value found as a string such as Nonce1 and then recall the API every few seconds till I get another Nonce value and name it Nonce2 for example? Is this possible? My code is down bellow.

from __future__ import print_function
import blocktrail

client = blocktrail.APIClient(api_key="x", api_secret="x", network="BTC", testnet=False)
address = client.address('x')

latest_block = client.block_latest()

nonce = latest_block['nonce']

print(nonce)

noncestr = str(nonce)
Sep 10, 2018 in Blockchain by slayer
• 29,050 points
24 views

2 answers to this question.

0 votes

A very simple-minded solution:

import time
nonce = "some string"
while True:
  latest_nonce = client.block_latest()['nonce']
  if latest_nonce != nonce:
     nonce = latest_nonce
  time.sleep(2)
answered Sep 10, 2018 by digger
• 27,630 points
0 votes

You can create a list and add your nonces to it:

nonces = []
nonces.append(yournonce)

Then you can access them like so:

nonces[noncenum]

You could use a while loop and time.sleep to get a new nonce every few seconds.

answered Sep 10, 2018 by Joy

Related Questions In Blockchain

0 votes
1 answer
0 votes
1 answer

Can I swap an ERC-20 token with a Neo NEP5 token using a smart contract?

Every Blockchain has a separate administration. So, it ...READ MORE

answered Jun 4, 2018 in Blockchain by Perry
• 17,010 points
79 views
0 votes
1 answer

Should I require a specific condition when working with indexes in Solidity?

You are using it correctly. require is intended to ...READ MORE

answered Jul 17, 2018 in Blockchain by ariaholic
• 7,320 points
23 views
0 votes
1 answer
0 votes
1 answer

Python request module for bitcoin json rpc

This should work: #!/usr/bin/env python import getpass import json import requests ...READ MORE

answered Aug 28, 2018 in Blockchain by digger
• 27,630 points
207 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
123 views
0 votes
1 answer

Korbit api with python http.client

http.client.HTTPSConnection accepts hostname, not a url. conn = http.client.HTTPSConnection("api.korbit.co.kr", ...READ MORE

answered Aug 28, 2018 in Blockchain by digger
• 27,630 points
132 views
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 27,630 points
2,475 views