@acryl/acryl-transactions 中文文档教程
acryl-transactions
使用此库,您可以轻松地为 Acryl 区块链创建和签署交易。 它还允许您对现有交易进行多重签名或创建它们而无需签名。
该库是一组交易构建函数:
- Alias
- Issue
- Reissue
- Burn
- Lease
- Cancel lease
- Transfer
- Mass transfer
- Set script
- Data
- Sponsorship
- Set asset script
- InvokeScript
- Order
查看 GitHub 页面 上的完整文档。
Transactions
这个想法非常简单——您创建交易并从所需的最少参数集对其进行签名。 如果您想创建转账交易,您至少需要提供金额 和 recipient 在 Transfer params 中定义:
const { transfer } = require('@acryl/acryl-transactions')
const seed = 'some example seed phrase'
const signedTranserTx = transfer({
amount: 1,
recipient: '3EKhM51MGZrq8FTnvKoTg95srTiC2Votx1B',
//Timestamp is optional but it was overrided, in case timestamp is not provided it will fallback to Date.now(). You can set any oftional params yourself. go check full docs
timestamp: 1536917842558
}, seed)
// or using alias
const signedTranserTx = transfer({
amount: 1,
recipient: 'alias:A:aliasForMyAddress'
}, seed)
输出将是签名的转账交易:
{
id: '8NrUwgKRCMFbUbqXKQAHkGnspmWHEjKUSi5opEC6Havq',
type: 4,
version: 2,
recipient: '3EKhM51MGZrq8FTnvKoTg95srTiC2Votx1B',
attachment: undefined,
feeAssetId: undefined,
assetId: undefined,
amount: 1,
fee: 100000,
senderPublicKey: '4MUrTiAwkVhRdkUj2Ya4LZbM7tGgd4sinLsGRZBvBvNa',
timestamp: 1536917842558,
proofs: [
'25kyX6HGjS3rkPTJRj5NVH6LLuZe6SzCzFtoJ8GDkojY9U5oPfVrnwBgrCHXZicfsmLthPUjTrfT9TQL2ciYrPGE'
]
}
您也可以创建交易,但不签名:
const unsignedTransferTx = transfer({
amount: 1,
recipient: '3EKhM51MGZrq8FTnvKoTg95srTiC2Votx1B',
//senderPublicKey is required if you omit seed
senderPublicKey: '4MUrTiAwkVhRdkUj2Ya4LZbM7tGgd4sinLsGRZBvBvNa'
})
现在您可以将其发布到 Acryl API 或存储以备将来使用,或者您可以添加另一方的另一个签名:
const otherPartySeed = 'other party seed phrase'
const transferSignedWithTwoParties = transfer(signedTranserTx, seed)
所以现在有两个证明:
{
id: '8NrUwgKRCMFbUbqXKQAHkGnspmWHEjKUSi5opEC6Havq',
type: 4,
version: 2,
recipient: '3EKhM51MGZrq8FTnvKoTg95srTiC2Votx1B',
attachment: undefined,
feeAssetId: undefined,
assetId: undefined,
amount: 1,
fee: 100000,
senderPublicKey: '4MUrTiAwkVhRdkUj2Ya4LZbM7tGgd4sinLsGRZBvBvNa',
timestamp: 1536917842558,
proofs: [
'25kyX6HGjS3rkPTJRj5NVH6LLuZe6SzCzFtoJ8GDkojY9U5oPfVrnwBgrCHXZicfsmLthPUjTrfT9TQL2ciYrPGE',
'CM9emPzpe6Ram7ZxcYax6s7Hkw6698wXCMPSckveFAS2Yh9vqJpy1X9nL7p4RKgU3UEa8c9RGXfUK6mFFq4dL9z'
]
}
Broadcast
发送您可以使用节点 REST API 或 broadcast 辅助函数:
const {broadcast} = require('@acryl/acryl-transactions');
const nodeUrl = 'https://nodes.acrylplatform.com';
broadcast(signedTx, nodeUrl).then(resp => console.log(resp))
Alias
Simlpe 别名创建示例:
const { alias } = require('@acryl/acryl-transactions')
const { broadcast } = require('@acryl/acryl-transactions');
const nodeUrl = 'https://nodes.acrylplatform.com';
const seed = 'some example seed phrase'
const signedAliasTx = alias({
alias: "someAlias"
//Timestamp is optional but it was overrided, in case timestamp is not provided it will fallback to Date.now(). You can set any oftional params yourself. go check full docs
timestamp: 1536917842558
}, seed);
broadcast(signedAliasTx, nodeUrl).then(resp => console.log(resp))
您可以将 tx 发送到您喜欢的任何 acryl 节点:。 例如:
- https://nodestestnet.acrylplatform.com - Acryl TESTNET nodes hosted by AcrylPlatform
- https://nodes.acrylplatform.com - Acryl MAINNET nodes hosted by AcrylPlatform
Important!!!
大多数交易都需要 chainId 作为参数,例如:IBurnParams。 默认情况下 chainId 是 'A',这意味着 MAINNET。 要在 TESTNET 中进行交易,请务必传递 chainId(如果它存在于参数接口中),然后将其发送到 TESTNET 节点
acryl-transactions
Using this library you can easily create and sign transactions for Acryl blockchain. It also allows you to multi-sign existing transactions or create them without signature at all.
This library is a set of transaction constructing functions:
- Alias
- Issue
- Reissue
- Burn
- Lease
- Cancel lease
- Transfer
- Mass transfer
- Set script
- Data
- Sponsorship
- Set asset script
- InvokeScript
- Order
Check full documentation on GitHub Pages.
Transactions
The idea is really simple - you create transaction and sign it from a minimal set of required params. If you want to create Transfer transaction the minimum you need to provide is amount and recipient as defined in Transfer params:
const { transfer } = require('@acryl/acryl-transactions')
const seed = 'some example seed phrase'
const signedTranserTx = transfer({
amount: 1,
recipient: '3EKhM51MGZrq8FTnvKoTg95srTiC2Votx1B',
//Timestamp is optional but it was overrided, in case timestamp is not provided it will fallback to Date.now(). You can set any oftional params yourself. go check full docs
timestamp: 1536917842558
}, seed)
// or using alias
const signedTranserTx = transfer({
amount: 1,
recipient: 'alias:A:aliasForMyAddress'
}, seed)
Output will be a signed transfer transaction:
{
id: '8NrUwgKRCMFbUbqXKQAHkGnspmWHEjKUSi5opEC6Havq',
type: 4,
version: 2,
recipient: '3EKhM51MGZrq8FTnvKoTg95srTiC2Votx1B',
attachment: undefined,
feeAssetId: undefined,
assetId: undefined,
amount: 1,
fee: 100000,
senderPublicKey: '4MUrTiAwkVhRdkUj2Ya4LZbM7tGgd4sinLsGRZBvBvNa',
timestamp: 1536917842558,
proofs: [
'25kyX6HGjS3rkPTJRj5NVH6LLuZe6SzCzFtoJ8GDkojY9U5oPfVrnwBgrCHXZicfsmLthPUjTrfT9TQL2ciYrPGE'
]
}
You can also create transaction, but not sign it:
const unsignedTransferTx = transfer({
amount: 1,
recipient: '3EKhM51MGZrq8FTnvKoTg95srTiC2Votx1B',
//senderPublicKey is required if you omit seed
senderPublicKey: '4MUrTiAwkVhRdkUj2Ya4LZbM7tGgd4sinLsGRZBvBvNa'
})
Now you are able to POST it to Acryl API or store for future purpose or you can add another signature from other party:
const otherPartySeed = 'other party seed phrase'
const transferSignedWithTwoParties = transfer(signedTranserTx, seed)
So now there are two proofs:
{
id: '8NrUwgKRCMFbUbqXKQAHkGnspmWHEjKUSi5opEC6Havq',
type: 4,
version: 2,
recipient: '3EKhM51MGZrq8FTnvKoTg95srTiC2Votx1B',
attachment: undefined,
feeAssetId: undefined,
assetId: undefined,
amount: 1,
fee: 100000,
senderPublicKey: '4MUrTiAwkVhRdkUj2Ya4LZbM7tGgd4sinLsGRZBvBvNa',
timestamp: 1536917842558,
proofs: [
'25kyX6HGjS3rkPTJRj5NVH6LLuZe6SzCzFtoJ8GDkojY9U5oPfVrnwBgrCHXZicfsmLthPUjTrfT9TQL2ciYrPGE',
'CM9emPzpe6Ram7ZxcYax6s7Hkw6698wXCMPSckveFAS2Yh9vqJpy1X9nL7p4RKgU3UEa8c9RGXfUK6mFFq4dL9z'
]
}
Broadcast
To send transaction you can use either node REST API or broadcast helper function:
const {broadcast} = require('@acryl/acryl-transactions');
const nodeUrl = 'https://nodes.acrylplatform.com';
broadcast(signedTx, nodeUrl).then(resp => console.log(resp))
Alias
Simlpe alias creation example:
const { alias } = require('@acryl/acryl-transactions')
const { broadcast } = require('@acryl/acryl-transactions');
const nodeUrl = 'https://nodes.acrylplatform.com';
const seed = 'some example seed phrase'
const signedAliasTx = alias({
alias: "someAlias"
//Timestamp is optional but it was overrided, in case timestamp is not provided it will fallback to Date.now(). You can set any oftional params yourself. go check full docs
timestamp: 1536917842558
}, seed);
broadcast(signedAliasTx, nodeUrl).then(resp => console.log(resp))
You can send tx to any acryl node you like:. E.g.:
- https://nodestestnet.acrylplatform.com - Acryl TESTNET nodes hosted by AcrylPlatform
- https://nodes.acrylplatform.com - Acryl MAINNET nodes hosted by AcrylPlatform
Important!!!
Most transactions require chainId as parameter, e.g: IBurnParams. By default chainId is 'A', which means MAINNET. To make transaction in TESTNET be sure to pass chainId if it is present in params interface and then send it to TESTNET node