· 7 years ago · Apr 04, 2018, 04:20 AM
1var MCoin = new StellarSdk.Asset('MCoin', 'GCKRPJXPGNHBPMRCXEX4MDH532BN5RLUJJOMVACA3CB7E2LWSTKTB5U2');
2var XLM = StellarSdk.Asset.native();
3server.loadAccount(distributor.publicKey)
4 .then(function(account){
5 var transaction = new StellarSdk.TransactionBuilder(account)
6 .addOperation(StellarSdk.Operation.manageOffer({
7 selling: MCoin ,
8 buying: XLM,
9 amount : '200',
10 price: 2,
11 offerId: 0,
12 }))
13 .build();
14 transaction.sign(distributorKeyPair);
15 //console.log(transaction.toEnvelope().toXDR('base64'));
16
17 server.submitTransaction(transaction)
18 .then(function(transactionResult){
19 //console.log(JSOn.stringify(transactionResult));
20 console.log('n Success!')
21 })
22 .catch(function(err){
23 console.log('An error has occured');
24 console.log(err);
25 })
26
27 })
28 .catch(function(e){
29 console.log(e);
30 })
31
32{ records:
33 [ { _links: [Object],
34 id: 221373,
35 paging_token: '221373',
36 seller: 'GB3K552PTUQB26X4LUNGPO7FN5GZGQAO2PXMKPCJ5A45ZJISANHFOHPR',
37 selling: [Object],
38 buying: [Object],
39 amount: '200.0000000',
40 price_r: [Object],
41 price: '2.0000000',
42 self: [Function],
43 offer_maker: [Function] },
44 { _links: [Object],
45 id: 221566,
46 paging_token: '221566',
47 seller: 'GB3K552PTUQB26X4LUNGPO7FN5GZGQAO2PXMKPCJ5A45ZJISANHFOHPR',
48 selling: [Object],
49 buying: [Object],
50 amount: '200.0000000',
51 price_r: [Object],
52 price: '2.0000000',
53 self: [Function],
54 offer_maker: [Function] } ],
55 next: [Function: next],
56 prev: [Function: prev] }
57
58var request = require('request');
59var StellarSdk = require('stellar-sdk');
60var server = new StellarSdk.Server('https://horizon-testnet.stellar.org');
61StellarSdk.Network.useTestNetwork();
62
63//account1
64pub1='GCBCTFOR2GES3JI5SKCYSDP7ZRIB523WQXZ5QC5FWXSK2FEMFMLJULIT'
65sec1='SB44SZ5IQCK72ELARVZ53BLSPO4NFCKH7H6ZBVGIFZ47CWLD5O2ADCOD'
66kp1=StellarSdk.Keypair.fromSecret(sec1)
67
68//account2
69pub2='GDNICVTW44YSI7BD6XB6GKPGCO6H367XT3JUFXG3XAFW46SOVKCBMPAI'
70sec2='SDIC6OCFXYLEBCJQIEDN5LN2KNVW4VZYY6FEGTIQ5CCSU7KLCPHRGIH4'
71kp2=StellarSdk.Keypair.fromSecret(sec2)
72
73distributor.publicKey=pub1
74distributorKeyPair=kp1
75
76var MCoin = new StellarSdk.Asset('MCoin', pub1);
77var XLM = StellarSdk.Asset.native();
78
79server.loadAccount(distributor.publicKey).then(function(account){
80 var transaction = new StellarSdk.TransactionBuilder(account)
81 .addOperation(StellarSdk.Operation.manageOffer({
82 selling: MCoin ,
83 buying: XLM,
84 amount : '200',
85 price: 2,
86 offerId: 0,
87 }))
88 .build();
89 transaction.sign(distributorKeyPair);
90 //console.log(transaction.toEnvelope().toXDR('base64'));
91
92 server.submitTransaction(transaction)
93 .then(function(transactionResult){
94 console.log(transactionResult);
95 console.log('n Success!')
96 })
97 .catch(function(err){
98 console.log('An error has occured');
99 console.log(err);
100 })
101
102 }).catch(function(e){
103 console.log(e);
104 })
105
106> distributorKeyPair
107Keypair {
108 type: 'ed25519',
109 _secretSeed: <Buffer 79 c9 67 a8 80 95 fd 11 60 8d 73 dd 85 72 7b b8 d2 89 47 f9 fd 90 d4 c8 2e 79 f1 59 63 eb b4 01>,
110 _secretKey: <Buffer 79 c9 67 a8 80 95 fd 11 60 8d 73 dd 85 72 7b b8 d2 89 47 f9 fd 90 d4 c8 2e 79 f1 59 63 eb b4 01 82 29 95 d1 d1 89 2d a5 1d 92 85 89 0d ff cc 50 1e eb ... >,
111 _publicKey: <Buffer 82 29 95 d1 d1 89 2d a5 1d 92 85 89 0d ff cc 50 1e eb 76 85 f3 d8 0b a5 b5 e4 ad 14 8c 2b 16 9a>,
112 publicKey: 'GCBCTFOR2GES3JI5SKCYSDP7ZRIB523WQXZ5QC5FWXSK2FEMFMLJULIT' }
113
114>
115>
116> distributor.publicKey
117'GCBCTFOR2GES3JI5SKCYSDP7ZRIB523WQXZ5QC5FWXSK2FEMFMLJULIT'