Receive
When to Use
How it works
const signer = KeetaNet.lib.Account.fromSeed(DEMO_ACCOUNT_SEED, 0);
const client = KeetaNet.UserClient.fromNetwork('test', signer);
// Addresses
const recipient = KeetaNet.lib.Account.fromPublicKeyString('<recipient-address>');
const sendToken = KeetaNet.lib.Account.fromPublicKeyString('<abc-token-address>');
const receiveToken = KeetaNet.lib.Account.fromPublicKeyString('<xyz-token-address>');
// Amounts (assumes you’ve already fetched decimals and validated)
const sendAmount = Numeric.fromDecimalString("10.0", 2); // 10 ABC
const receiveAmount = Numeric.fromDecimalString("5.0", 2); // 5 XYZ
// Create transaction
const builder = client.initBuilder();
builder.send(recipient, sendAmount.valueOf(), sendToken);
builder.receive(recipient, receiveAmount.valueOf(), receiveToken, true);
// Compute the transaction block (not yet published)
const { blocks } = await client.computeBuilderBlocks(builder);
// This unsigned block can now be signed and published by the other party
const unsignedBytes = blocks[0].toBytes();
console.log("📦 Unsigned swap block ready for signature:", unsignedBytes);Signature Flow:
Last updated