-
Notifications
You must be signed in to change notification settings - Fork 2
/
5_purchaseToken.js
54 lines (44 loc) · 1.1 KB
/
5_purchaseToken.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const {
accounts: { issuer, buyer },
serverUrl
} = require("./config.json");
const {
Server,
Networks,
Asset,
TransactionBuilder,
Operation,
Keypair
} = require("stellar-sdk");
const server = new Server(serverUrl);
const main = async () => {
const buyerAccount = await server.loadAccount(buyer.publicKey);
const breadAsset = new Asset("BRD", issuer.publicKey);
const txOptions = {
fee: await server.fetchBaseFee(),
networkPassphrase: Networks.TESTNET
};
const changeTrustOpts = {
asset: breadAsset,
limit: "500"
};
const manageSellOfferOpts = {
selling: Asset.native(),
buying: breadAsset,
amount: "1",
price: "1"
};
const transaction = new TransactionBuilder(buyerAccount, txOptions)
.addOperation(Operation.changeTrust(changeTrustOpts))
.addOperation(Operation.manageSellOffer(manageSellOfferOpts))
.setTimeout(0)
.build();
transaction.sign(Keypair.fromSecret(buyer.secret));
await server.submitTransaction(transaction);
};
main()
.then(() => console.log("ok"))
.catch(e => {
console.log("Meh", e);
throw e;
});