-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquest1.kt
45 lines (38 loc) · 1.37 KB
/
quest1.kt
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
package set2
import Keys
import friendBot
import org.stellar.sdk.*
import java.security.MessageDigest
fun main() {
val server = Server("https://horizon-testnet.stellar.org")
val questAccountKeys = KeyPair.fromSecretSeed(Keys.quest2PrivateKey)
// Need helper account to create with exactly 5000XLM
val creatorAccountKeys = KeyPair.random()
println("helper: ${creatorAccountKeys.accountId}")
creatorAccountKeys.friendBot()
val creatorAccount = server.accounts().account(creatorAccountKeys.accountId)
val txBuilder = Transaction.Builder(creatorAccount, Network.TESTNET)
.addMemo(Memo.hash("Stellar Quest Series 2".sha256()))
.setBaseFee(FeeBumpTransaction.MIN_BASE_FEE)
.setTimeout(180)
txBuilder.addOperation(
CreateAccountOperation.Builder(questAccountKeys.accountId, "5000").build()
)
val transaction = txBuilder.build()
transaction.sign(creatorAccountKeys)
println("Executing tx..")
try {
val response = server.submitTransaction(transaction)
println("Success!")
println("txHash: ${response.hash}")
println("result: ${response.resultXdr.get()}")
} catch (e: Exception) {
println("Something went wrong!")
println(e.message)
}
}
fun String.sha256(): ByteArray {
return MessageDigest
.getInstance("SHA-256")
.digest(this.toByteArray())
}