Operation API
Introduction
When creating a HyMatrix instance, you provide accid, privateKey, signer, arJWK, and url.
accid: Account address.
privateKey: Ethereum private key, consisting of '0x' + 64 characters, total 66 characters.
arJWK: Arweave JWKInterface JSON file oruse_wallet.
signer: Ethereum signer created vianew Web3Provider(window.ethereum). You can also exportWeb3Providerfromhymatrix-js.
url: Node URL to send requests to.
info
- In the HyMatrix network environment, each
processIdis assigned a fixed node to handle transactions. - Before sending a transaction, use getNodesByProcess to get the nodes corresponding to the
processId. - When creating a
HyMatrixinstance, you can configure the node with theurlfield.
const hyMatrix = new HyMatrix({
url: 'https / http'
})
When sending a sendMessage transaction, pass processId, tags, and optional data:
export interface SendMessageParams {
processId: string
tags: Tag[]
data?: string
}
export interface Tag {
name: string
value: string
}
processId: string type, representing the ID of the process.
tags: Tag type, including fields like Action, Recipient, Quantity.
data: string type, representing the data to be signed.
// processId
const processId = ''
const recipient = ''
const amt = '100'
const tags = [
{ name: 'Action', value: 'Transfer' },
{ name: 'Recipient', value: recipient },
{ name: 'Quantity', value: amt }
]
sendMessage
Send a transaction via the Hymatrix network.
Parameter
| Field | Required | Description |
|---|---|---|
| processId | YES | processId: process address |
| tags | YES | Tag type, for example, for a transfer tags should include [{ name: 'Action', value: 'Transfer' }, { name: 'Recipient', value: 'addr' }, { name: 'Quantity', value: 'amt' }] |
| data | NO | Signed data, optional, defaults to empty string. |
Example
// Transfer example: using hmAR
// 1. Confirm the transfer processId
const processId = 'GuuH1wCOBatG-JoKu42NkJMC7Cx-rjD8F5EEICLTNP8'
// 2. Confirm recipient address and amount
const recipient = '' // ethAddress or arAddress
const amt = '100' // transfer amount
const tags = [
{ name: 'Action', value: 'Transfer' },
{ name: 'Recipient', value: recipient },
{ name: 'Quantity', value: amt }
]
// 3. Get the node URLs by processId to successfully send the transaction
// If you already know the url, you can skip this step to reduce requests and save time
const urls = await new HyMatrix().getNodesByProcess(processId)
// 4. Create a HyMatrix instance
const hyMatrix = new HyMatrix({
arJWK: 'use_wallet',
url: urls[0]?.URL // all subsequent requests will be sent to this URL
})
// 5. Build params object
const params = {
tags,
processId,
data: '' // optional, defaults to empty string
}
// 6. Send transaction
const result = await hyMatrix.sendMessage(params)
console.log(result.id) // get message ID, can be used to query transaction details
// wait a moment...
// 7. Query transaction details // tip: request sent to configured URL node
const resultTx = await hyMatrix.getResult(processId, result.id)
console.log(resultTx) // get detailed transaction info
Example return
{
"id": "vDDowE3NrNKfAyZtfEGaTLrkOhr3DDB2D_-Vs22Z8ig"
}