Skip to content

Commit 600e28d

Browse files
committed
Update the exchange integration doc
1 parent f3d2ae1 commit 600e28d

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

docs/integration/exchange.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,69 @@ curl -X 'POST' \
145145
# }
146146
```
147147

148+
You can also use the `/transactions/build` endpoint to build a token transfer transaction:
149+
150+
```shell
151+
curl -X 'POST' \
152+
'http://127.0.0.1:22973/transactions/build' \
153+
-H 'accept: application/json' \
154+
-H 'Content-Type: application/json' \
155+
-d '{
156+
"fromPublicKey": "0381818e63bd9e35a5489b52a430accefc608fd60aa2c7c0d1b393b5239aedf6b0",
157+
"destinations": [
158+
{
159+
"address": "1C2RAVWSuaXw8xtUxqVERR7ChKBE1XgscNFw73NSHE1v3",
160+
"tokens": [
161+
{
162+
"id": "19246e8c2899bc258a1156e08466e3cdd3323da756d8a543c7fc911847b96f00",
163+
"amount": "1000000000000000000"
164+
}
165+
],
166+
}
167+
]
168+
}'
169+
```
170+
171+
In addition to using the raw endpoint, you can also refer to [this guide](../sdk/transaction.md) on how to use the `@alephium/web3` SDK to build and send transactions.
172+
173+
The `@alephium/web3` SDK also provides APIs to extract ALPH and token deposits from a transaction:
174+
175+
```typescript
176+
import { getALPHDepositInfo, getDepositInfo, getSenderAddress } from '@alephium/web3'
177+
178+
// extract ALPH deposit info from a transaction
179+
const alphDepositInfo = getALPHDepositInfo(tx)
180+
// [
181+
// {
182+
// targetAddress: '1khyjTYdKEyCSyg6SqyDf97Vq3EmSJF9zPugb3KYERP8',
183+
// depositAmount: 1000000000000000000n
184+
// }
185+
// ]
186+
187+
// get the sender address of the deposit transaction
188+
const senderAddress = getSenderAddress(tx)
189+
190+
// extract ALPH and token deposit info from a transaction
191+
const depositInfo = getDepositInfo(tx)
192+
// {
193+
// alph: [
194+
// {
195+
// targetAddress: '1khyjTYdKEyCSyg6SqyDf97Vq3EmSJF9zPugb3KYERP8',
196+
// depositAmount: 1000000000000000000n
197+
// }
198+
// ],
199+
// tokens: [
200+
// {
201+
// tokenId: '19246e8c2899bc258a1156e08466e3cdd3323da756d8a543c7fc911847b96f00',
202+
// targetAddress: '1khyjTYdKEyCSyg6SqyDf97Vq3EmSJF9zPugb3KYERP8',
203+
// depositAmount: 1000000000000000000n
204+
// }
205+
// ]
206+
// }
207+
```
208+
209+
You can filter the deposit information sent to your exchange address by `targetAddress` and `tokenId`.
210+
148211
## Block APIs
149212

150213
### Get block hash with transaction ID

docs/sdk/transaction.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,25 @@ const buildTxResult = await builder.buildTransferTx(
9292
console.log('unsigned transaction', buildTxResult.unsignedTx)
9393
```
9494

95+
You can also use `builtTransferTx` to build a token transfer transaction:
96+
97+
```typescript
98+
const buildTxResult = await builder.buildTransferTx(
99+
{
100+
signerAddress: senderAddress,
101+
destinations: [{
102+
address: receiverAddress,
103+
tokens: [{
104+
id: '19246e8c2899bc258a1156e08466e3cdd3323da756d8a543c7fc911847b96f00',
105+
amount: 1000000000000000000n
106+
}]
107+
}]
108+
},
109+
senderPublicKey
110+
)
111+
console.log('unsigned transaction', buildTxResult.unsignedTx)
112+
```
113+
95114
### Execute Script Transaction
96115

97116
Let's build an unsigned transaction to execute a transaction script.

0 commit comments

Comments
 (0)