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,370 points
873 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
• 26,740 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,100 points
984 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 aryya
• 7,460 points
587 views
0 votes
1 answer

How do I add multiple recipients for transactions via Blockchain API?

Convert the recipes into JSON objects. x = ...READ MORE

answered Jul 6, 2018 in Blockchain by Perry
• 17,100 points
885 views
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
• 26,740 points
2,363 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
1,923 views
0 votes
2 answers

Trying to issue tokens on testnet with python API

By looking at - documentation here I think you ...READ MORE

answered Sep 17, 2018 in Blockchain by Khush
848 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
• 26,740 points
1,420 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
• 26,740 points
45,219 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP