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']


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

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
answered Sep 10, 2018 by digger
• 26,720 points
0 votes

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

nonces = []

Then you can access them like so:


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
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,440 points
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
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,720 points
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,830 points
0 votes
1 answer

Korbit api with python http.client

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

answered Aug 28, 2018 in Blockchain by digger
• 26,720 points
+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,720 points