-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpayment.js
44 lines (37 loc) · 983 Bytes
/
payment.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
const {
Networks,
Server,
TransactionBuilder,
Operation,
Keypair,
Asset
} = require("stellar-sdk");
const { alice, bob } = require("./accounts");
const server = new Server("https://horizon-testnet.stellar.org");
const alicePaymentToBob = async () => {
const txOptions = {
fee: await server.fetchBaseFee(),
networkPassphrase: Networks.TESTNET
};
const aliceAccount = await server.loadAccount(alice.publicKey);
const paymentTx = new TransactionBuilder(aliceAccount, txOptions)
.addOperation(
Operation.payment({
amount: "1",
asset: Asset.native(),
destination: bob.publicKey
})
)
.setTimeout(0)
.build();
paymentTx.sign(Keypair.fromSecret(alice.secret));
// paymentTx.sign(Keypair.fromSecret(bob.secret));
await server.submitTransaction(paymentTx);
};
alicePaymentToBob()
.then(() => {
console.log("ok");
})
.catch(e => {
console.log(e.response.data.extras.result_codes);
});