Skip to content

Instantly share code, notes, and snippets.

@webmaster128
Last active September 25, 2019 18:53
Show Gist options
  • Save webmaster128/9b06fce3415d1f49ac7849224f93b0a0 to your computer and use it in GitHub Desktop.
Save webmaster128/9b06fce3415d1f49ac7849224f93b0a0 to your computer and use it in GitHub Desktop.
Example code how to return escrows using the IOV-Core CLI on Catnet 🐈
const nodeUrl = "wss://rpc-private-a-vip-catnet.iov.one";
const mnemonic = "twin document gold guide asset false rival rib civil squeeze they upper";
const escrowIds = [3, 4, 8, 10, 22, 34, 46, 58];
const profile = new UserProfile();
const signer = new MultiChainSigner(profile);
const { connection } = await signer.addChain(createBnsConnector(nodeUrl));
const chainId = connection.chainId();
const wallet = profile.addWallet(Ed25519HdWallet.fromMnemonic(mnemonic));
// any identity that can pay the fees
const friend = await profile.createIdentity(wallet.id, chainId, HdPaths.iov(0))
const friendAddress = signer.identityToAddress(friend);
console.log("Address", friendAddress);
for (const escrowId of escrowIds) {
console.log("Returning escrow", escrowId);
const tx = await connection.withDefaultFee<ReturnEscrowTx & WithCreator>({
kind: "bns/return_escrow",
creator: friend,
escrowId: escrowId,
});
const postResult = await signer.signAndPost(tx);
const blockInfo = await postResult.blockInfo.waitFor(info => !isBlockInfoPending(info));
if (!isBlockInfoSucceeded(blockInfo)) {
throw new Error("Transaction failed");
}
console.log("Successfully returned escrow", escrowId)
}
Address tiov1cxyg7gw9t600qzczyrru4m97sckyty0s4cmkzm
Returning escrow 3
Successfully returned escrow 3
Returning escrow 4
Successfully returned escrow 4
Returning escrow 8
Successfully returned escrow 8
Returning escrow 10
Successfully returned escrow 10
Returning escrow 22
Successfully returned escrow 22
Returning escrow 34
Successfully returned escrow 34
Returning escrow 46
Successfully returned escrow 46
Returning escrow 58
Successfully returned escrow 58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment