Skip to content

Instantly share code, notes, and snippets.

@leon-do
Last active December 31, 2018 06:37
Show Gist options
  • Save leon-do/98fc02fa8858374200df2c4d28066aa6 to your computer and use it in GitHub Desktop.
Save leon-do/98fc02fa8858374200df2c4d28066aa6 to your computer and use it in GitHub Desktop.
// load escrow account from pub key
const escrowAccount = await blockchain.loadAccount(escrowPubKey)
// build claim transaction with timelock
const tb = new stellarSdk.TransactionBuilder(escrowAccount, {
timebounds: {
minTime: Math.floor(Date.now() / 1000) + 3600, // this envelope is valid after 1 hour
maxTime: 0
}
})
.addOperation(
stellarSdk.Operation.payment({
destination: serverKeyPair.publicKey(),
asset: stellarSdk.Asset.native(),
amount: '2.00001' // send upfront cost back to server
}))
.addOperation(
stellarSdk.Operation.accountMerge({
destination: userPubKey // merge remainder back to user
}))
.build()
// sign transaction
tx.sign(serverKeyPair)
// https://www.stellar.org/developers/js-stellar-sdk/reference/examples.html
const refundEnvelope = tx.toEnvelope().toXDR('base64')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment