1- var arkjs = require ( "arkjs" ) ;
2- var fs = require ( 'fs' ) ;
3- var XMLHttpRequest = require ( "xmlhttprequest" ) . XMLHttpRequest ;
1+ const fs = require ( 'fs' ) ;
2+ const Connection = require ( "@arkecosystem/client" ) . Connection ;
3+ const Crypto = require ( "@arkecosystem/crypto" ) . Crypto ;
4+ const Managers = require ( "@arkecosystem/crypto" ) . Managers ;
5+ const Transactions = require ( "@arkecosystem/crypto" ) . Transactions ;
6+ const Identities = require ( "@arkecosystem/crypto" ) . Identities ;
7+
8+ // Global var
9+ Managers . configManager . setConfig (
10+ JSON . parse ( fs . readFileSync ( "networks.json" , "utf8" ) )
11+ ) ;
12+
13+ const client = new Connection ( "http://testnet.osmose.world:4003/api/v2" ) ;
414
515module . exports = {
616 CheckAddress : function ( address ) {
7- return arkjs . crypto . validateAddress ( address , 115 ) ;
17+ return Identities . Address . validate ( address , 65 ) ;
818 } ,
9- SendOSM : function ( address ) {
10- let wallet = JSON . parse ( fs . readFileSync ( 'config.json' , 'utf8' ) ) . faucetWallet ;
11- let nethash = "fa976091894eee4cad258bdae4e3323d0768c4f8610e471237408ac4aa0a92d0" ;
12- let sender = arkjs . crypto . getKeys ( wallet ) ;
13- let amountSatoshi = 1000 * Math . pow ( 10 , 8 ) ;
19+ SendOSM : async function ( address ) {
20+ const walletPassphrase = JSON . parse ( fs . readFileSync ( 'config.json' , 'utf8' ) ) . faucetWallet . normalize ( 'NFD' ) ;
21+ const sender = Identities . Address . fromPublicKey ( Identities . Keys . fromPassphrase ( walletPassphrase ) . publicKey , 65 ) ;
22+ const amountoOSMtoshi = 100 * Math . pow ( 10 , 8 ) ;
1423
15- let transaction = arkjs . transaction . createTransaction ( address , amountSatoshi , "Courtesy of our faucet" , sender , undefined , 115 ) ;
24+ const data = "Courtesy from OSMOSE Faucet"
1625
17- let transactions = {
18- transactions : [ transaction ]
19- }
26+ let transaction = Transactions . BuilderFactory
27+ . transfer ( )
28+ . amount ( `${ amountoOSMtoshi } ` )
29+ . recipientId ( address )
30+ . network ( 65 )
31+ . vendorField ( data )
32+ . sign ( walletPassphrase ) ;
2033
21- let http = new XMLHttpRequest ( ) ;
22- let url = 'http://blockchain.osmose.world:4100/peer/transactions' ;
23- http . open ( 'POST' , url , true ) ;
24- http . setRequestHeader ( "nethash" , nethash ) ;
25- http . setRequestHeader ( "version" , "1.6.0" ) ;
26- http . setRequestHeader ( "port" , "1" ) ;
27-
28- //Send the proper header information along with the request
29- http . setRequestHeader ( "Content-Type" , "application/json" ) ;
30-
31- http . onreadystatechange = function ( ) {
32- if ( http . readyState === 4 && http . status === 200 ) {
33- console . log ( new Date ( ) + " | 1000 OSM sent from : " + arkjs . crypto . getAddress ( sender . publicKey , 115 ) + " --> " + address ) ;
34+ const response = await client . api ( "transactions" ) . create ( { transactions : [ transaction . getStruct ( ) ] } ) ;
35+
36+ if ( response . status === 200 ) {
37+ if ( response . body . errors )
38+ console . log ( 'Error during transaction, please check if there is a valid passphrase in config.json file' ) ;
39+ else
40+ {
41+ console . log ( new Date ( ) + " | 100 OSM sent from : " + sender + " --> " + address ) ;
42+ return true ;
3443 }
35- } ;
44+ }
3645
37- http . send ( JSON . stringify ( transactions ) ) ;
46+ return false ;
3847 }
3948} ;
0 commit comments