Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

Sponsored Reserves Example

node v10.24.1
version: master
endpointsharetweet
const { Keypair, Server, Networks, Operation, TransactionBuilder, BASE_FEE } = require('stellar-sdk') const parseError = require('@runkit/tyvdh/parse-error/2.0.0') const sponsorKeypair = Keypair.fromSecret('SAJ43ZK2Q6XEKKXOHXTTI72WIL2LEFG5S2DD77YQMDA3QBTVCB2IGN4X') const sponsorPublicKey = sponsorKeypair.publicKey() const sponsoredKeypair = Keypair.fromSecret('SBR2SBM5U6ZFE7YGFVRSWQH2M2CYSG4YSF7RMXCBHELXZVWPTVGHAF6Y') const sponsoredPublicKey = sponsoredKeypair.publicKey() const server = new Server('https://horizon-testnet.stellar.org') // Sponsor createAccount Reserve await server.loadAccount(sponsorPublicKey) .then((account) => { const transaction = new TransactionBuilder(account, { fee: BASE_FEE, networkPassphrase: Networks.TESTNET }) .addOperation(Operation.beginSponsoringFutureReserves({ sponsoredId: sponsoredPublicKey })) .addOperation(Operation.createAccount({ destination: sponsoredPublicKey, startingBalance: '0', })) .addOperation(Operation.endSponsoringFutureReserves({ source: sponsoredPublicKey })) .setTimeout(0) .build() transaction.sign(sponsorKeypair, sponsoredKeypair) return transaction.toXDR() // return server.submitTransaction(transaction) }) .then((res) => console.log(res)) .catch((err) => console.error(parseError(err))) // Revoke createAccount Sponsorship // await server.loadAccount(sponsorPublicKey) // .then((account) => { // const transaction = new TransactionBuilder(account, { // fee: BASE_FEE, // networkPassphrase: Networks.TESTNET // }) // .addOperation(Operation.revokeAccountSponsorship({ // account: sponsoredPublicKey // })) // .setTimeout(0) // .build() // transaction.sign(sponsorKeypair) // return transaction.toXDR() // // return server.submitTransaction(transaction) // }) // .then((res) => console.log(res)) // .catch((err) => console.error(parseError(err)))
Loading…

no comments

    sign in to comment