High-level API
Transaction helpers are high-level functions built into the OCAP Client that abstract away the complexity of creating and signing common transactions. Instead of manually constructing transaction objects, you can use these convenient methods for workflows like creating assets, transferring tokens, staking, and performing atomic swaps. These helpers ensure that the transaction structure is correct and simplify the development process significantly.
For a deeper understanding of the underlying transaction lifecycle, see Core Concepts: Transaction Lifecycle.
Account Management#
migrateAccount#
Migrates the ownership of an account to a new key pair. This is useful for key rotation or account recovery.
Parameters
Returns
Example
Send an AccountMigrateTx
const txHash = await client.migrateAccount({
from: oldWallet,
to: newWallet,
});
console.log('Migration transaction hash:', txHash);delegate#
Authorizes another account (the delegatee) to send specific types of transactions on behalf of the delegator. This is a powerful feature for creating secure, sandboxed permissions.
Parameters
Returns
Example
Send a DelegateTx
const [txHash, delegateAddress] = await client.delegate({
from: userWallet,
to: appWallet,
privileges: [
{
typeUrl: 'fg:t:transfer_v2',
},
],
});
console.log('Delegation tx hash:', txHash);
console.log('Delegate address:', delegateAddress);revokeDelegate#
Revokes previously granted permissions from a delegatee.
Parameters
Returns
Example
Send a RevokeDelegateTx
const txHash = await client.revokeDelegate({
from: userWallet,
to: appWallet,
privileges: ['fg:t:transfer_v2'],
});
console.log('Revocation tx hash:', txHash);Asset (NFT) Management#
createAsset#
Creates a new asset (Non-Fungible Token) on the blockchain.
Parameters
Returns
Example
Send a CreateAssetTx
const [txHash, assetAddress] = await client.createAsset({
moniker: 'My First NFT',
data: {
typeUrl: 'json',
value: { name: 'Digital Collectible', description: 'A unique item.' },
},
wallet: userWallet,
});
console.log('Create asset tx hash:', txHash);
console.log('New asset address:', assetAddress);updateAsset#
Updates the moniker and data fields of an existing, non-readonly asset.
Parameters
Returns
Example
Send an UpdateAssetTx
const txHash = await client.updateAsset({
address: 'z3g...',
moniker: 'Updated NFT Name',
data: {
typeUrl: 'json',
value: { name: 'Updated Collectible', description: 'Now with more features!' },
},
wallet: userWallet,
});
console.log('Update asset tx hash:', txHash);createAssetFactory#
Creates an asset factory, which acts as a template for minting multiple new assets with a consistent structure.
Parameters
Returns
Example
Send a CreateFactoryTx
const factoryConfig = {
name: 'Ticket Factory',
description: 'Mints event tickets',
limit: 1000,
input: { ... },
output: { ... },
};
const [txHash, factoryAddress] = await client.createAssetFactory({
factory: factoryConfig,
wallet: eventCreatorWallet,
});
console.log('Create factory tx hash:', txHash);
console.log('New factory address:', factoryAddress);acquireAsset#
Acquires (mints) a new asset from an existing asset factory. This is typically initiated by the end-user who will own the asset.
Parameters
Returns
Example
Send an AcquireAssetV2Tx
// First, prepare the minting transaction (e.g., on the server)
const itx = await client.preMintAsset({
factory: factoryAddress,
owner: userWallet.address,
wallet: issuerWallet,
});
// Then, the user sends the transaction
const txHash = await client.acquireAsset({ itx, wallet: userWallet });
console.log('Acquire asset tx hash:', txHash);mintAsset#
This is the issuer-side counterpart to acquireAsset. It allows a trusted issuer to mint an asset from a factory and assign it to a specified owner.
Parameters
Returns
Example
Send a MintAssetTx
const itx = await client.preMintAsset({
factory: factoryAddress,
owner: userWallet.address,
wallet: issuerWallet,
});
const txHash = await client.mintAsset({ itx, wallet: issuerWallet });
console.log('Mint asset tx hash:', txHash);Token Management#
createTokenFactory#
Creates a new factory for minting and burning a specific fungible token, often based on a bonding curve pricing model.
Parameters
The configuration for the token to be created. This includes properties like name, symbol, decimal, and maxTotalSupply.
Returns
Example
Send a CreateTokenFactoryTx
const [txHash, factoryAddress] = await client.createTokenFactory({
feeRate: 100, // 1%
curve: { fixedPrice: '1' }, // 1 native token per new token
token: {
name: 'My Community Token',
symbol: 'MCT',
decimal: 18,
maxTotalSupply: '1000000',
},
wallet: creatorWallet,
});
console.log('Create token factory tx hash:', txHash);
console.log('New token factory address:', factoryAddress);updateTokenFactory#
Updates the feeRate and data for an existing token factory.
Parameters
Returns
Example
Send an UpdateTokenFactoryTx
const txHash = await client.updateTokenFactory({
address: 'z2f...',
feeRate: 50, // 0.5%
wallet: ownerWallet,
});
console.log('Update token factory tx hash:', txHash);mintToken#
Mints new tokens from a token factory in exchange for the reserve token (usually the native chain token). The cost is determined by the factory's bonding curve.
Parameters
Returns
Example
Send a MintTokenTx
const txHash = await client.mintToken({
tokenFactory: 'z2f...',
amount: 100,
receiver: userWallet.address,
maxReserve: 105, // Willing to pay up to 105 native tokens
wallet: userWallet,
});
console.log('Mint token tx hash:', txHash);burnToken#
Burns existing tokens at a factory to receive the underlying reserve token in return. The amount of reserve token received is determined by the factory's bonding curve.
Parameters
Returns
Example
Send a BurnTokenTx
const txHash = await client.burnToken({
tokenFactory: 'z2f...',
amount: 50,
receiver: userWallet.address,
minReserve: 48, // Expecting to receive at least 48 native tokens
wallet: userWallet,
});
console.log('Burn token tx hash:', txHash);Transfer & Exchange#
transfer#
Transfers native tokens, custom fungible tokens, and/or assets (NFTs) to another account in a single transaction.
Parameters
Returns
Example
Send a TransferV2Tx
const txHash = await client.transfer({
to: 'z1sb...',
token: 1.5, // 1.5 of the native chain token
assets: ['z3g...'], // An NFT
tokens: [{ address: 'z2t...', value: 100 }], // 100 of a custom token
memo: 'Payment for services',
wallet: senderWallet,
});
console.log('Transfer tx hash:', txHash);prepareExchange#
Prepares the sender's half of an atomic swap (exchange) transaction. It signs the sender's offer and returns a transaction object that can be passed to the receiver.
Parameters
Returns
finalizeExchange#
Finalizes the receiver's half of an atomic swap. It takes the partially signed transaction from prepareExchange, adds the receiver's signature, and returns the fully signed transaction object.
Parameters
Returns
exchange#
Sends the fully signed exchange transaction to the blockchain. This can be called by either party after finalizeExchange is complete.
Parameters
Returns
Example (Full Exchange Flow)
Perform an atomic swap
// 1. Offerer prepares the transaction
const offerTx = await client.prepareExchange({
receiver: receiverWallet.address,
offerAssets: ['z3g...'], // Offer an NFT
demandToken: 10, // Demand 10 native tokens
wallet: offererWallet,
});
// 2. Receiver finalizes the transaction
const finalTx = await client.finalizeExchange({
tx: offerTx,
wallet: receiverWallet,
});
// 3. Either party can send the finalized transaction
const txHash = await client.exchange({ tx: finalTx, wallet: offererWallet });
console.log('Exchange tx hash:', txHash);Staking#
stake#
Stakes tokens and/or assets to a receiver address. Staking locks up resources, often in exchange for rewards or to provide security.
Parameters
Returns
Example
Send a StakeTx
const [txHash, stakeAddress] = await client.stake({
to: 'z1v...',
tokens: [{ address: 'z2t...', value: 5000 }],
message: 'Staking for validator rewards',
wallet: userWallet,
});
console.log('Stake tx hash:', txHash);
console.log('New stake address:', stakeAddress);revokeStake#
Revokes previously staked tokens and/or assets, initiating the process to return them to the owner. Note that there may be an unbonding period before the assets can be claimed.
Parameters
Returns
Example
Send a RevokeStakeTx
const txHash = await client.revokeStake({
from: 'z6s...',
tokens: [{ address: 'z2t...', value: 1000 }],
wallet: userWallet,
});
console.log('Revoke stake tx hash:', txHash);claimStake#
Claims items from a stake that have been successfully revoked and have passed their unbonding period.
Parameters
Returns
Example
Send a ClaimStakeTx
const revokeTxHash = '0x123...abc';
const txHash = await client.claimStake({
from: 'z6s...',
evidence: revokeTxHash,
wallet: userWallet,
});
console.log('Claim stake tx hash:', txHash);slashStake#
Allows a designated slasher to penalize a stake, typically for misbehavior. The slashed assets are transferred to a designated vault address.
Parameters
Returns
Example
Send a SlashStakeTx
const txHash = await client.slashStake({
from: 'z6s...',
reason: 'Validator downtime',
tokens: [{ address: 'z2t...', value: 500 }],
wallet: slasherWallet,
});
console.log('Slash stake tx hash:', txHash);