SJCL
This commit is contained in:
52
src/Scripts/Testnet.js
Normal file
52
src/Scripts/Testnet.js
Normal file
@@ -0,0 +1,52 @@
|
||||
/*Public Key
|
||||
GDY2CP7XLBIY65YX7KS72X7JCZJVJ3AEPEEFTW3TYPLGDRWEZKAC7NR3
|
||||
Secret Key
|
||||
SAM4KRGZ4YTAQV3XK3FRKVHZV77AA37KSYZLKZ4OZSX3SBWR6C6NYS4M
|
||||
*/
|
||||
import StellarSdk from 'stellar-sdk'
|
||||
const server = new StellarSdk.Server('https://horizon-testnet.stellar.org'); // const server = new StellarSdk.Server('https://horizon.stellar.org');
|
||||
const fee = await server.fetchBaseFee();
|
||||
export default function getAccount(privatekey){
|
||||
const keypair = StellarSdk.Keypair.fromSecret(privatekey)
|
||||
return server.loadAccount(keypair.publicKey())
|
||||
}
|
||||
export function send(amount, privatekey, destination){
|
||||
const keypair = StellarSdk.Keypair.fromSecret(privatekey)
|
||||
server.loadAccount(keypair.publicKey()).then(account => {
|
||||
console.log(account)
|
||||
const transaction = new StellarSdk.TransactionBuilder(account, {fee, networkPassphrase: StellarSdk.Networks.TESTNET})
|
||||
// Add a payment operation to the transaction
|
||||
.addOperation(StellarSdk.Operation.payment({
|
||||
destination: destination,
|
||||
// The term native asset refers to lumens
|
||||
asset: new StellarSdk.Asset("BLC", "GBPKUSD5ZGMEXCS5YW7WAOC2QJSJLEX6LHGUTJIMDYYPFLPOT6GYFNNX"),
|
||||
// Specify 350.1234567 lumens. Lumens are divisible to seven digits past
|
||||
// the decimal. They are represented in JS Stellar SDK in string format
|
||||
// to avoid errors from the use of the JavaScript Number data structure.
|
||||
amount: amount,
|
||||
}))
|
||||
// Make this transaction valid for the next 30 seconds only
|
||||
.setTimeout(30)
|
||||
// Uncomment to add a memo (https://www.stellar.org/developers/learn/concepts/transactions.html)
|
||||
// .addMemo(StellarSdk.Memo.text('Hello world!'))
|
||||
.build();
|
||||
|
||||
// Sign this transaction with the secret key
|
||||
// NOTE: signing is transaction is network specific. Test network transactions
|
||||
// won't work in the public network. To switch networks, use the Network object
|
||||
// as explained above (look for StellarSdk.Network).
|
||||
transaction.sign(keypair)
|
||||
try {
|
||||
server.submitTransaction(transaction);
|
||||
} catch (e) {
|
||||
console.log('An error has occured:');
|
||||
console.log(e);
|
||||
}
|
||||
});
|
||||
|
||||
// Let's see the XDR (encoded in base64) of the transaction we just built
|
||||
|
||||
// Submit the transaction to the Horizon server. The Horizon server will then
|
||||
// submit the transaction into the network for us.
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user