I wanna generate 1000 testnet accounts onetime,so I tried the request+for loop,
the below is my ### code:
1 var StellarSdk=require('stellar-sdk');
2 var request=require('request');
3 var fs=require("fs");
4
5 var writeStream=fs.createWriteStream('address.txt');
6
7 var count=1000;
8 console.log("begin generating address\n********************************");
9
10 for (let index=1;index<=count;index++){
11 if (index%100==0){
12 console.log((new Date()).toLocaleString());
13 console.log("have generate %d address",index);
14 console.log("completion of progress %s%",(index/count*100).toFixed(2));
15 }
16 var pair=StellarSdk.Keypair.random();
17 writeStream.write(pair.publicKey()+'\n','UTF8');
18
19 request.get({
20 // this url does not work
21 // url:'https://horizon-testnet.stellar.org/friendbot',
22 url:'https://friendbot.stellar.org',
23 qs:{ addr:pair.publicKey() },
24 json:true
25 },function(error,response,body){
26 if(error||response.statusCode!==200) {
27 console.error('ERROR',error||body);
28 }
29 else {
30 // console.log('SUCCESS!You have a new account :)\n',pair.publicKey());
31 }
32 });
33
34 }
35
36 console.log("***********************************\n\n\nAll %d address have been generated successfully",count);
37 writeStream.end();
but the errors occured,just like the below:
ERROR { type: 'https://stellar.org/horizon-errors/server_error',
38 title: 'Internal Server Error',
39 status: 500,
40 detail: 'An error occurred while processing this request. This is usually due to a bug within the server software. Trying this request again may succeed if the bug is transient, ot herwise please report this issue to the issue tracker at: https://github.com/stellar/go/services/horizon/internal/issues. Please include this response in your issue.' }
Is there something wrong with the request function?Is it asynchronous??
If it is,how should I fix my code?
Or,the stellar prevent me to generate so many account onetime?
Thanks,guys!