Would you like to clone this notebook?

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

Cancel

Claimable Balance Example

node v14.20.1
version: master
endpointsharetweet
const { Keypair, Server, Networks, Operation, TransactionBuilder, BASE_FEE, Asset, Claimant } = require('stellar-sdk') const sponsorKeypair = Keypair.fromSecret('SDTFXB2CB4LQ4RJR4F4STJF5AECME7B2SSGYONSRCLQOWTOB7UJ3TZAL') const sponsorPublicKey = sponsorKeypair.publicKey() const sponsoredKeypair = Keypair.fromSecret('SDOYKIGS2V63HWBLUUCBZHJDUYUAI3CS5PWFCGWZQBOKHZF3FMON7NXZ') const sponsoredPublicKey = sponsoredKeypair.publicKey() const server = new Server('https://horizon-testnet.stellar.org') // Create Claimable Balance // await server.loadAccount(sponsorPublicKey) // .then((account) => { // const transaction = new TransactionBuilder(account, { // fee: BASE_FEE, // networkPassphrase: Networks.TESTNET // }) // .addOperation(Operation.createClaimableBalance({ // asset: Asset.native(), // amount: '100', // claimants: [ // new Claimant(sponsoredPublicKey) // ], // })) // .setTimeout(0) // .build() // transaction.sign(sponsorKeypair) // // return transaction.toXDR() // return server.submitTransaction(transaction) // }) // .catch(({response: {data}}) => console.error(data)) // Claim Claimable Balance await server.loadAccount(sponsoredPublicKey) .then(async (account) => { // await account.claimableBalances() :( const { records } = await server .claimableBalances() .claimant(account.id) .call() if (!records.length) return const transaction = new TransactionBuilder(account, { fee: BASE_FEE, networkPassphrase: Networks.TESTNET }) .addOperation(Operation.claimClaimableBalance({ balanceId: records[0].id })) .setTimeout(0) .build() transaction.sign(sponsoredKeypair) // return transaction.toXDR() return server.submitTransaction(transaction) })
Loading…

no comments

    sign in to comment