hts/initiateSwap
How to call the API from an app
const snapId = `npm:@hashgraph/hedera-wallet-snap`
const initiateSwapAPI = async () => {
const externalAccountParams = {
externalAccount: {
accountIdOrEvmAddress: '0.0.12345',
curve: 'ED25519'
}
}
const requester = {
assetType: 'HBAR', // 'HBAR' | 'TOKEN' | 'NFT'
to: '0.0.1',
amount: 1
}
const responder = {
assetType: 'TOKEN', // 'HBAR' | 'TOKEN' | 'NFT'
amount: 10,
assetId: '0.0.4279119' // For NFT, the format is tokenId/serialNumber
}
await window.ethereum.request({
method: 'wallet_invokeSnap',
params: {
snapId,
request: {
method: 'hts/initiateSwap',
params: {
network: 'testnet',
atomicSwaps: [{
requester,
responder
}],
memo?: // Optional param - type string
maxFee?: // Optional param - type number(in hbars)
/*
Uncomment the below line if you want to connect
to a non-metamask account
*/
// ...externalAccountParams
}
}
}
})
}What the API does
Example of how the Atomic Swap is performed

Live Demo on CodePen
Last updated
Was this helpful?

