Skip to content

Commit

Permalink
Merge pull request #473 from alephium/update-exchange-integration-doc
Browse files Browse the repository at this point in the history
Update the exchange integration doc
  • Loading branch information
polarker authored Dec 17, 2024
2 parents f3d2ae1 + 600e28d commit cf91910
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
63 changes: 63 additions & 0 deletions docs/integration/exchange.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,69 @@ curl -X 'POST' \
# }
```

You can also use the `/transactions/build` endpoint to build a token transfer transaction:

```shell
curl -X 'POST' \
'http://127.0.0.1:22973/transactions/build' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"fromPublicKey": "0381818e63bd9e35a5489b52a430accefc608fd60aa2c7c0d1b393b5239aedf6b0",
"destinations": [
{
"address": "1C2RAVWSuaXw8xtUxqVERR7ChKBE1XgscNFw73NSHE1v3",
"tokens": [
{
"id": "19246e8c2899bc258a1156e08466e3cdd3323da756d8a543c7fc911847b96f00",
"amount": "1000000000000000000"
}
],
}
]
}'
```

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.

The `@alephium/web3` SDK also provides APIs to extract ALPH and token deposits from a transaction:

```typescript
import { getALPHDepositInfo, getDepositInfo, getSenderAddress } from '@alephium/web3'

// extract ALPH deposit info from a transaction
const alphDepositInfo = getALPHDepositInfo(tx)
// [
// {
// targetAddress: '1khyjTYdKEyCSyg6SqyDf97Vq3EmSJF9zPugb3KYERP8',
// depositAmount: 1000000000000000000n
// }
// ]

// get the sender address of the deposit transaction
const senderAddress = getSenderAddress(tx)

// extract ALPH and token deposit info from a transaction
const depositInfo = getDepositInfo(tx)
// {
// alph: [
// {
// targetAddress: '1khyjTYdKEyCSyg6SqyDf97Vq3EmSJF9zPugb3KYERP8',
// depositAmount: 1000000000000000000n
// }
// ],
// tokens: [
// {
// tokenId: '19246e8c2899bc258a1156e08466e3cdd3323da756d8a543c7fc911847b96f00',
// targetAddress: '1khyjTYdKEyCSyg6SqyDf97Vq3EmSJF9zPugb3KYERP8',
// depositAmount: 1000000000000000000n
// }
// ]
// }
```

You can filter the deposit information sent to your exchange address by `targetAddress` and `tokenId`.

## Block APIs

### Get block hash with transaction ID
Expand Down
19 changes: 19 additions & 0 deletions docs/sdk/transaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,25 @@ const buildTxResult = await builder.buildTransferTx(
console.log('unsigned transaction', buildTxResult.unsignedTx)
```

You can also use `builtTransferTx` to build a token transfer transaction:

```typescript
const buildTxResult = await builder.buildTransferTx(
{
signerAddress: senderAddress,
destinations: [{
address: receiverAddress,
tokens: [{
id: '19246e8c2899bc258a1156e08466e3cdd3323da756d8a543c7fc911847b96f00',
amount: 1000000000000000000n
}]
}]
},
senderPublicKey
)
console.log('unsigned transaction', buildTxResult.unsignedTx)
```

### Execute Script Transaction

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

0 comments on commit cf91910

Please sign in to comment.