1

I'm getting an op_cannot_claim error code, when trying to claim claimable balance.

I've checked the docs, they don't mention this error code at all.

let account = await server.loadAccount(pairA.publicKey());

// Create a claimable balance with our two above-described conditions.
let soon = Math.ceil(Date.now() / 1000 + 60); // .now() is in ms
let bCanClaim = Stellar.Claimant.predicateBeforeRelativeTime("60");
let aCanReclaim = Stellar.Claimant.predicateNot(
  Stellar.Claimant.predicateBeforeAbsoluteTime(soon.toString())
);

// Create the operation and submit it in a transaction.
let claimableBalanceEntry = Stellar.Operation.createClaimableBalance({
  claimants: [
    new Stellar.Claimant(pairB.publicKey(), bCanClaim),
    new Stellar.Claimant(pairA.publicKey(), aCanReclaim),
  ],
  asset: Stellar.Asset.native(),
  amount: "420",
});

let tx = new Stellar.TransactionBuilder(account, { fee: Stellar.BASE_FEE })
  .addOperation(claimableBalanceEntry)
  .setNetworkPassphrase(Stellar.Networks.TESTNET)
  .setTimeout(180)
  .build();

// signing transaction
var keypair = Stellar.Keypair.fromSecret(pairA.secret());
tx.sign(keypair);

server
  .submitTransaction(tx)
  .then(function () {
    console.log("Claimable balance created!");
  })
  .catch(function (err) {
    console.error(`Tx submission failed: ${err}`);
  });

let balances = await server
  .claimableBalances()
  .claimant(pairB.publicKey())
  .limit(1) // there may be many in general
  .order("desc") // so always get the latest one
  .call()
  .catch(function (err) {
   console.error(`Claimable balance retrieval failed: ${err}`);
});

let balanceId = balances.records[0].id;

let claimBalance = Stellar.Operation.claimClaimableBalance({
  balanceId: balanceId,
});

console.log(pairB.publicKey(), "claiming", balanceId);

let tx1 = new Stellar.TransactionBuilder(account, { fee: Stellar.BASE_FEE })
  .addOperation(claimBalance)
  .setNetworkPassphrase(Stellar.Networks.TESTNET)
  .setTimeout(180)
  .build();

let key = Stellar.Keypair.fromSecret(pairA.secret());
tx1.sign(key);

server.submitTransaction(tx1).catch(function (err) {
  console.error(err);
});

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.