/
send-transaction.js
88 lines (73 loc) · 3.96 KB
/
send-transaction.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const OverledgerSDK = require('@quantnetwork/overledger-bundle').default;
// ---------------------------------------------------------
// -------------- BEGIN VARIABLES TO UPDATE ----------------
// ---------------------------------------------------------
const mappId = '<ENTER YOUR MAPPID>';
const bpiKey = '<ENTER YOUR BPIKEY>';
// Paste in your ethereum and ripple private keys.
// For Ethereum you can generate an account using `OverledgerSDK.dlts.ethereum.createAccount` then fund the address at the Ropsten Testnet Faucet.
const partyAEthereumPrivateKey = '0xe352ad01a835ec50ba301ed7ffb305555cbf3b635082af140b3864f8e3e443d3';
const partyAEthereumAddress = '0x650A87cfB9165C9F4Ccc7B971D971f50f753e761'
// For Ripple, you can go to the official Ripple Testnet Faucet to get an account already funded.
const partyARipplePrivateKey = 'sswERuW1KWEwMXF6VFpRY72PxfC9b';
const partyARippleAddress = 'rhTa8RGotyJQAW8sS2tFVVfvcHYXaps9hC'
const partyBEthereumAddress = '0x1a90dbb13861a29bFC2e464549D28bE44846Dbe4';
// Keep in mind that for Ripple, the minimum transfer amount is 20XRP (20,000,000 drops), if the address is not yet funded.
const partyBRippleAddress = 'rHVsZPVPjYJMR3Xa8YH7r7MapS7s5cyqgB';
// ---------------------------------------------------------
// -------------- END VARIABLES TO UPDATE ------------------
// ---------------------------------------------------------
const overledger = new OverledgerSDK(mappId, bpiKey, {
dlts: [{ dlt: 'ethereum' }, { dlt: 'ripple' }],
provider: {
network: 'testnet',
timeout: 10000,
},
});
const transactionMessage = 'Hello world!';
; (async () => {
try {
// SET partyA accounts for signing;
overledger.dlts.ethereum.setAccount(partyAEthereumPrivateKey);
overledger.dlts.ripple.setAccount(partyARipplePrivateKey);
// Get the address sequences.
const ethereumSequenceRequest = await overledger.dlts.ethereum.getSequence(partyAEthereumAddress);
const rippleSequenceRequest = await overledger.dlts.ripple.getSequence(partyARippleAddress);
const ethereumAccountSequence = ethereumSequenceRequest.data.dltData[0].sequence;
const rippleAccountSequence = rippleSequenceRequest.data.dltData[0].sequence;
console.log("The transaction sequence of our Ethereum account is: ", ethereumAccountSequence);
console.log("The transaction sequence of our Ripple account is: ", rippleAccountSequence);
// Sign the transactions.
const signedTransactions = await overledger.sign([
{
// In order to prepare an ethereum transaction offline, we have to specify the sequence (nonce), a feePrice (gasPrice) and feeLimit (gasLimit).
dlt: 'ethereum',
toAddress: partyBEthereumAddress,
message: transactionMessage,
options: {
amount: '0', // On Ethereum you can send 0 amount transactions. But you still pay network fees
sequence: ethereumAccountSequence, // Sequence starts at 0 for newly created addresses
feePrice: '1000', // Price for each individual gas unit this transaction will consume
feeLimit: '80000', // The maximum fee that this transaction will use
},
},
{
// In order to prepare a ripple transaction offline, we have to specify a fee, sequence and maxLedgerVersion.
dlt: 'ripple',
toAddress: partyBRippleAddress,
message: transactionMessage,
options: {
amount: '1', // Minimum allowed amount of drops is 1.
sequence: rippleAccountSequence, // Sequence increases by 1 with each transaction and starts at 1 right after getting the address from the XRP testnet faucet.
feePrice: '12', // Minimum feePrice on Ripple is 12 drops.
maxLedgerVersion: '4294967295', // The maximum ledger version the transaction can be included in.
},
},]);
// Send the transactions to Overledger.
const result = (await overledger.send(signedTransactions)).data;
// Log the result.
console.log(JSON.stringify(result, null, 2));
} catch (e) {
console.error('error:', e);
}
})();