openchain-nodejs-ts-yxl 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +66 -0
  3. package/_config.yml +1 -0
  4. package/doc/SDK_CN.md +2003 -0
  5. package/example/atp10TokenDemo.js +319 -0
  6. package/example/exchange.js +184 -0
  7. package/example/offlineSignatureDemo.js +83 -0
  8. package/example/submitTransactionDemo.js +92 -0
  9. package/index.d.ts +186 -0
  10. package/index.js +9 -0
  11. package/lib/account/index.js +234 -0
  12. package/lib/blockchain/block.js +380 -0
  13. package/lib/blockchain/transaction.js +264 -0
  14. package/lib/common/ctp.js +5 -0
  15. package/lib/common/operation/accountSetMetadata.js +55 -0
  16. package/lib/common/operation/accountSetPrivilege.js +90 -0
  17. package/lib/common/operation/activateAccount.js +58 -0
  18. package/lib/common/operation/contractCreate.js +72 -0
  19. package/lib/common/operation/contractInvokeByAsset.js +75 -0
  20. package/lib/common/operation/contractInvokeByBU.js +53 -0
  21. package/lib/common/operation/createLog.js +44 -0
  22. package/lib/common/operation/ctp10TokenApprove.js +59 -0
  23. package/lib/common/operation/ctp10TokenAssign.js +59 -0
  24. package/lib/common/operation/ctp10TokenChangeOwner.js +58 -0
  25. package/lib/common/operation/ctp10TokenIssue.js +78 -0
  26. package/lib/common/operation/ctp10TokenTransfer.js +59 -0
  27. package/lib/common/operation/ctp10TokenTransferFrom.js +60 -0
  28. package/lib/common/operation/issueAsset.js +35 -0
  29. package/lib/common/operation/payAsset.js +62 -0
  30. package/lib/common/operation/payCoin.js +44 -0
  31. package/lib/common/util.js +880 -0
  32. package/lib/contract/index.js +212 -0
  33. package/lib/crypto/protobuf/bundle.json +1643 -0
  34. package/lib/exception/customErrors.js +56 -0
  35. package/lib/exception/errors.js +240 -0
  36. package/lib/exception/index.js +8 -0
  37. package/lib/operation/account.js +193 -0
  38. package/lib/operation/asset.js +106 -0
  39. package/lib/operation/bu.js +52 -0
  40. package/lib/operation/contract.js +184 -0
  41. package/lib/operation/ctp10Token.js +394 -0
  42. package/lib/operation/index.js +30 -0
  43. package/lib/operation/log.js +47 -0
  44. package/lib/sdk.js +70 -0
  45. package/lib/token/asset.js +79 -0
  46. package/lib/token/ctp10Token.js +301 -0
  47. package/lib/token/index.js +17 -0
  48. package/lib/util/index.js +86 -0
  49. package/openchain-sdk-nodejs.iml +9 -0
  50. package/package.json +39 -0
  51. package/test/Ctp10Token.test.js +96 -0
  52. package/test/account.test.js +132 -0
  53. package/test/accountActivateOperation.test.js +99 -0
  54. package/test/accountSetMetadata.test.js +102 -0
  55. package/test/accountSetPrivilege.test.js +66 -0
  56. package/test/asset.test.js +63 -0
  57. package/test/assetIssueOperation.test.js +77 -0
  58. package/test/assetSendOperation.test.js +103 -0
  59. package/test/blob.test.js +128 -0
  60. package/test/block.test.js +165 -0
  61. package/test/buSendOperation.test.js +64 -0
  62. package/test/contract.test.js +64 -0
  63. package/test/contractCreateOperation.test.js +41 -0
  64. package/test/contractCreateTransaction.test.js +116 -0
  65. package/test/contractInvokeByAssetOperation.test.js +109 -0
  66. package/test/contractInvokeByBUOperation.test.js +107 -0
  67. package/test/ctp10TokenApproveOperation.test.js +98 -0
  68. package/test/ctp10TokenAssignOperation.test.js +99 -0
  69. package/test/ctp10TokenChangeOwnerOperation.test.js +98 -0
  70. package/test/ctp10TokenIssueOperation.test.js +40 -0
  71. package/test/ctp10TokenIssueOperationTransaction.test.js +106 -0
  72. package/test/ctp10TokenTransferFromOperation.test.js +101 -0
  73. package/test/ctp10TokenTransferOperation.test.js +98 -0
  74. package/test/log.transaction.test.js +103 -0
  75. package/test/transaction.test.js +166 -0
  76. package/test/util.test.js +93 -0
@@ -0,0 +1,107 @@
1
+ 'use strict';
2
+
3
+ require('chai').should();
4
+ const BigNumber = require('bignumber.js');
5
+ const co = require('co');
6
+
7
+ const OpenChainSDK = require('../index');
8
+
9
+ const sdk = new OpenChainSDK({
10
+ host: 'localhost/node/api',
11
+ });
12
+
13
+ describe('Test contract Invoke By BU transaction', function() {
14
+
15
+ it('test contract Invoke By BU' , function() {
16
+
17
+ const privateKey = 'private key';
18
+ const sourceAddress = 'adxScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3r';
19
+ const contractAddress = 'adxSqKcX8wGCMKhzNUBoDWfbeQaMhfnGdtyG2';
20
+ // const contractAddress = 'adxScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3r';
21
+ co(function* () {
22
+ const result = yield sdk.account.getNonce(sourceAddress);
23
+
24
+ if (result.errorCode !== 0) {
25
+ console.log(result);
26
+ return;
27
+ }
28
+ let nonce = result.result.nonce;
29
+
30
+ nonce = new BigNumber(nonce).plus(1).toString(10);
31
+
32
+ let contractInvokeByBUOperation = yield sdk.operation.contractInvokeByBUOperation({
33
+ contractAddress,
34
+ sourceAddress,
35
+ buAmount: '0',
36
+ input: 'aaaa',
37
+ // metadata: 'Test contract create operation',
38
+ });
39
+
40
+ if (contractInvokeByBUOperation.errorCode !== 0) {
41
+ console.log(contractInvokeByBUOperation);
42
+ return;
43
+ }
44
+
45
+ // console.log(contractInvokeByBUOperation);
46
+ // return;
47
+ const operationItem = contractInvokeByBUOperation.result.operation;
48
+
49
+ const args = {
50
+ sourceAddress,
51
+ nonce,
52
+ operations: [operationItem],
53
+ signtureNumber: '100',
54
+ // metadata: 'Test evaluation fee',
55
+ };
56
+
57
+ let feeData = yield sdk.transaction.evaluateFee(args);
58
+ if (feeData.errorCode !== 0) {
59
+ console.log(feeData);
60
+ return;
61
+ }
62
+
63
+ let feeLimit = feeData.result.feeLimit;
64
+ let gasPrice = feeData.result.gasPrice;
65
+
66
+ // 2. build blob
67
+ let blobInfo = sdk.transaction.buildBlob({
68
+ sourceAddress: sourceAddress,
69
+ gasPrice,
70
+ feeLimit,
71
+ nonce: nonce,
72
+ operations: [ operationItem ],
73
+ });
74
+
75
+ if (blobInfo.errorCode !== 0) {
76
+ console.log(blobInfo);
77
+ return;
78
+ }
79
+
80
+ let blob = blobInfo.result.transactionBlob;
81
+
82
+ // 3. sign blob
83
+ let signatureInfo = sdk.transaction.sign({
84
+ privateKeys: [ privateKey ],
85
+ blob,
86
+ });
87
+
88
+ if (signatureInfo.errorCode !== 0) {
89
+ console.log(signatureInfo);
90
+ return;
91
+ }
92
+
93
+ let signature = signatureInfo.result.signatures;
94
+ // 4. submit transaction
95
+ let transactionInfo = yield sdk.transaction.submit({
96
+ blob,
97
+ signature: signature,
98
+ });
99
+
100
+ console.log(transactionInfo);
101
+
102
+ }).catch(err => {
103
+ console.log(err);
104
+ });
105
+ });
106
+
107
+ });
@@ -0,0 +1,98 @@
1
+ 'use strict';
2
+
3
+ require('chai').should();
4
+ const BigNumber = require('bignumber.js');
5
+ const co = require('co');
6
+
7
+ const OpenChainSDK = require('../index');
8
+
9
+ const sdk = new OpenChainSDK({
10
+ host: 'localhost/node/api',
11
+ // host: '192.168.1.34:36002',
12
+ });
13
+
14
+ describe('Test ctp10Token Approve Operation', function() {
15
+
16
+ it('Test ctp10Token Approve Operation', async() => {
17
+ const privateKey = 'private key';
18
+ let sourceAddress = 'adxScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3r';
19
+ const result = await sdk.account.getNonce(sourceAddress);
20
+
21
+ if (result.errorCode !== 0) {
22
+ console.log(result);
23
+ return;
24
+ }
25
+ let nonce = result.result.nonce;
26
+
27
+ nonce = new BigNumber(nonce).plus(1).toString(10);
28
+
29
+ let ctp10TokenApproveOperation = await sdk.operation.ctp10TokenApproveOperation({
30
+ contractAddress: 'adxSqKcX8wGCMKhzNUBoDWfbeQaMhfnGdtyG2',
31
+ spender: 'adxSqKcX8wGCMKhzNUBoDWfbeQaMhfnGdtyG2',
32
+ tokenAmount: '1',
33
+ sourceAddress,
34
+ // metadata: '',
35
+ });
36
+
37
+ if (ctp10TokenApproveOperation.errorCode !== 0) {
38
+ console.log(ctp10TokenApproveOperation);
39
+ return;
40
+ }
41
+
42
+ const operationItem = ctp10TokenApproveOperation.result.operation;
43
+
44
+ const args = {
45
+ sourceAddress,
46
+ nonce,
47
+ operations: [operationItem],
48
+ signtureNumber: '100',
49
+ // metadata: 'Test evaluation fee',
50
+ };
51
+
52
+ let feeData = await sdk.transaction.evaluateFee(args);
53
+ if (feeData.errorCode !== 0) {
54
+ console.log(feeData);
55
+ return;
56
+ }
57
+
58
+ let feeLimit = feeData.result.feeLimit;
59
+ let gasPrice = feeData.result.gasPrice;
60
+
61
+ // 2. build blob
62
+ let blobInfo = sdk.transaction.buildBlob({
63
+ sourceAddress: sourceAddress,
64
+ gasPrice,
65
+ feeLimit,
66
+ nonce: nonce,
67
+ operations: [ operationItem ],
68
+ });
69
+
70
+ if (blobInfo.errorCode !== 0) {
71
+ console.log(blobInfo);
72
+ return;
73
+ }
74
+
75
+ let blob = blobInfo.result.transactionBlob;
76
+
77
+ // 3. sign blob
78
+ let signatureInfo = sdk.transaction.sign({
79
+ privateKeys: [ privateKey ],
80
+ blob,
81
+ });
82
+
83
+ if (signatureInfo.errorCode !== 0) {
84
+ console.log(signatureInfo);
85
+ return;
86
+ }
87
+
88
+ let signature = signatureInfo.result.signatures;
89
+ // 4. submit transaction
90
+ let transactionInfo = await sdk.transaction.submit({
91
+ blob,
92
+ signature: signature,
93
+ });
94
+
95
+ console.log(transactionInfo);
96
+ });
97
+
98
+ });
@@ -0,0 +1,99 @@
1
+ 'use strict';
2
+
3
+ require('chai').should();
4
+ const BigNumber = require('bignumber.js');
5
+ const co = require('co');
6
+
7
+ const OpenChainSDK = require('../index');
8
+
9
+ const sdk = new OpenChainSDK({
10
+ host: 'localhost/node/api',
11
+ // host: '192.168.1.34:36002',
12
+ });
13
+
14
+ describe('Test ctp10Token Transfer Operation', function() {
15
+
16
+ it('Test ctp10Token Transfer Operation', async() => {
17
+
18
+ const privateKey = 'private key';
19
+ let sourceAddress = 'adxScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3r';
20
+ const result = await sdk.account.getNonce(sourceAddress);
21
+
22
+ if (result.errorCode !== 0) {
23
+ console.log(result);
24
+ return;
25
+ }
26
+ let nonce = result.result.nonce;
27
+
28
+ nonce = new BigNumber(nonce).plus(1).toString(10);
29
+
30
+ let ctp10TokenTransferOperation = await sdk.operation.ctp10TokenAssignOperation({
31
+ contractAddress: 'adxSqKcX8wGCMKhzNUBoDWfbeQaMhfnGdtyG2',
32
+ destAddress: 'adxScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3r',
33
+ tokenAmount: '20',
34
+ // sourceAddress,adxScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3r
35
+ // metadata: '',
36
+ });
37
+
38
+ if (ctp10TokenTransferOperation.errorCode !== 0) {
39
+ console.log(ctp10TokenTransferOperation);
40
+ return;
41
+ }
42
+
43
+ const operationItem = ctp10TokenTransferOperation.result.operation;
44
+
45
+ const args = {
46
+ sourceAddress,
47
+ nonce,
48
+ operations: [operationItem],
49
+ signtureNumber: '100',
50
+ // metadata: 'Test evaluation fee',
51
+ };
52
+
53
+ let feeData = await sdk.transaction.evaluateFee(args);
54
+ if (feeData.errorCode !== 0) {
55
+ console.log(feeData);
56
+ return;
57
+ }
58
+
59
+ let feeLimit = feeData.result.feeLimit;
60
+ let gasPrice = feeData.result.gasPrice;
61
+
62
+ // 2. build blob
63
+ let blobInfo = sdk.transaction.buildBlob({
64
+ sourceAddress: sourceAddress,
65
+ gasPrice,
66
+ feeLimit,
67
+ nonce: nonce,
68
+ operations: [ operationItem ],
69
+ });
70
+
71
+ if (blobInfo.errorCode !== 0) {
72
+ console.log(blobInfo);
73
+ return;
74
+ }
75
+
76
+ let blob = blobInfo.result.transactionBlob;
77
+
78
+ // 3. sign blob
79
+ let signatureInfo = sdk.transaction.sign({
80
+ privateKeys: [ privateKey ],
81
+ blob,
82
+ });
83
+
84
+ if (signatureInfo.errorCode !== 0) {
85
+ console.log(signatureInfo);
86
+ return;
87
+ }
88
+
89
+ let signature = signatureInfo.result.signatures;
90
+ // 4. submit transaction
91
+ let transactionInfo = await sdk.transaction.submit({
92
+ blob,
93
+ signature: signature,
94
+ });
95
+
96
+ console.log(transactionInfo);
97
+ });
98
+
99
+ });
@@ -0,0 +1,98 @@
1
+ 'use strict';
2
+
3
+ require('chai').should();
4
+ const BigNumber = require('bignumber.js');
5
+ const co = require('co');
6
+
7
+ const OpenChainSDK = require('../index');
8
+
9
+ const sdk = new OpenChainSDK({
10
+ host: 'localhost/node/api',
11
+ // host: '192.168.1.34:36002',
12
+ });
13
+
14
+ describe('Test ctp10Token Change Owner Operation', function() {
15
+
16
+ it('Test ctp10Token Change Owner Operation', async() => {
17
+ const privateKey = 'private key';
18
+ let sourceAddress = 'adxScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3r';
19
+ const result = await sdk.account.getNonce(sourceAddress);
20
+
21
+ if (result.errorCode !== 0) {
22
+ console.log(result);
23
+ return;
24
+ }
25
+ let nonce = result.result.nonce;
26
+
27
+ nonce = new BigNumber(nonce).plus(1).toString(10);
28
+
29
+ let ctp10TokenApproveOperation = await sdk.operation.ctp10TokenChangeOwnerOperation({
30
+ contractAddress: 'adxSqKcX8wGCMKhzNUBoDWfbeQaMhfnGdtyG2',
31
+ tokenOwner: 'adxSqKcX8wGCMKhzNUBoDWfbeQaMhfnGdtyG2',
32
+ sourceAddress,
33
+ // metadata: '',
34
+ });
35
+
36
+ if (ctp10TokenApproveOperation.errorCode !== 0) {
37
+ console.log(ctp10TokenApproveOperation);
38
+ return;
39
+ }
40
+
41
+ const operationItem = ctp10TokenApproveOperation.result.operation;
42
+
43
+ const args = {
44
+ sourceAddress,
45
+ nonce,
46
+ operations: [operationItem],
47
+ signtureNumber: '100',
48
+ // metadata: 'Test evaluation fee',
49
+ };
50
+
51
+ let feeData = await sdk.transaction.evaluateFee(args);
52
+
53
+ if (feeData.errorCode !== 0) {
54
+ console.log(feeData);
55
+ return;
56
+ }
57
+
58
+ let feeLimit = feeData.result.feeLimit;
59
+ let gasPrice = feeData.result.gasPrice;
60
+
61
+ // 2. build blob
62
+ let blobInfo = sdk.transaction.buildBlob({
63
+ sourceAddress: sourceAddress,
64
+ gasPrice,
65
+ feeLimit,
66
+ nonce: nonce,
67
+ operations: [ operationItem ],
68
+ });
69
+
70
+ if (blobInfo.errorCode !== 0) {
71
+ console.log(blobInfo);
72
+ return;
73
+ }
74
+
75
+ let blob = blobInfo.result.transactionBlob;
76
+
77
+ // 3. sign blob
78
+ let signatureInfo = sdk.transaction.sign({
79
+ privateKeys: [ privateKey ],
80
+ blob,
81
+ });
82
+
83
+ if (signatureInfo.errorCode !== 0) {
84
+ console.log(signatureInfo);
85
+ return;
86
+ }
87
+
88
+ let signature = signatureInfo.result.signatures;
89
+ // 4. submit transaction
90
+ let transactionInfo = await sdk.transaction.submit({
91
+ blob,
92
+ signature: signature,
93
+ });
94
+
95
+ console.log(transactionInfo);
96
+ });
97
+
98
+ });
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+
3
+ require('chai').should();
4
+ const BigNumber = require('bignumber.js');
5
+ const co = require('co');
6
+
7
+ const OpenChainSDK = require('../index');
8
+
9
+ const sdk = new OpenChainSDK({
10
+ host: 'localhost/node/api',
11
+ // host: '192.168.1.34:36002',
12
+ });
13
+
14
+ describe('Test ctp10Token Issue Operation', function() {
15
+
16
+ it('Test ctp10Token Issue Operation ', function() {
17
+ let data = sdk.operation.ctp10TokenIssueOperation({
18
+ initBalance: '10000000',
19
+ name: 'leo',
20
+ symbol: 'LEO',
21
+ decimals: 6,
22
+ totalSupply: '30',
23
+ sourceAddress: 'adxScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3r',
24
+ // metadata: '',
25
+ });
26
+ data.errorCode.should.equal(0);
27
+
28
+ data = sdk.operation.ctp10TokenIssueOperation({
29
+ initBalance: '10000000a',
30
+ name: 'leo',
31
+ symbol: 'LEO',
32
+ decimals: 6,
33
+ totalSupply: '30',
34
+ sourceAddress: 'adxScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3r',
35
+ metadata: '',
36
+ });
37
+ data.errorCode.should.equal(11004);
38
+ });
39
+
40
+ });
@@ -0,0 +1,106 @@
1
+ 'use strict';
2
+
3
+ require('chai').should();
4
+ const BigNumber = require('bignumber.js');
5
+ const co = require('co');
6
+
7
+ const OpenChainSDK = require('../index');
8
+
9
+ const sdk = new OpenChainSDK({
10
+ host: 'localhost/node/api',
11
+ // host: '192.168.1.34:36002',
12
+ });
13
+
14
+ describe('Test ctp10Token Issue Transaction', function() {
15
+
16
+ it('Test ctp10Token Issue Transaction ', function() {
17
+ const privateKey = 'private key';
18
+ const sourceAddress = 'adxScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3r';
19
+
20
+ co(function* () {
21
+ const result = yield sdk.account.getNonce(sourceAddress);
22
+
23
+ if (result.errorCode !== 0) {
24
+ console.log(result);
25
+ return;
26
+ }
27
+ let nonce = result.result.nonce;
28
+
29
+ nonce = new BigNumber(nonce).plus(1).toString(10);
30
+
31
+ let ctp10TokenIssueOperation = sdk.operation.ctp10TokenIssueOperation({
32
+ initBalance: '2000000000',
33
+ name: 'leo',
34
+ symbol: 'LEO',
35
+ decimals: 6,
36
+ totalSupply: '50',
37
+ sourceAddress,
38
+ // metadata: '',
39
+ });
40
+
41
+ if (ctp10TokenIssueOperation.errorCode !== 0) {
42
+ console.log(ctp10TokenIssueOperation);
43
+ return;
44
+ }
45
+
46
+ const operationItem = ctp10TokenIssueOperation.result.operation;
47
+
48
+ const args = {
49
+ sourceAddress,
50
+ nonce,
51
+ operations: [operationItem],
52
+ signtureNumber: '100',
53
+ // metadata: 'Test evaluation fee',
54
+ };
55
+
56
+ let feeData = yield sdk.transaction.evaluateFee(args);
57
+ if (feeData.errorCode !== 0) {
58
+ console.log(feeData);
59
+ return;
60
+ }
61
+
62
+ let feeLimit = feeData.result.feeLimit;
63
+ let gasPrice = feeData.result.gasPrice;
64
+
65
+ // 2. build blob
66
+ let blobInfo = sdk.transaction.buildBlob({
67
+ sourceAddress: sourceAddress,
68
+ gasPrice,
69
+ feeLimit,
70
+ nonce: nonce,
71
+ operations: [ operationItem ],
72
+ });
73
+
74
+ if (blobInfo.errorCode !== 0) {
75
+ console.log(blobInfo);
76
+ return;
77
+ }
78
+
79
+ let blob = blobInfo.result.transactionBlob;
80
+
81
+ // 3. sign blob
82
+ let signatureInfo = sdk.transaction.sign({
83
+ privateKeys: [ privateKey ],
84
+ blob,
85
+ });
86
+
87
+ if (signatureInfo.errorCode !== 0) {
88
+ console.log(signatureInfo);
89
+ return;
90
+ }
91
+
92
+ let signature = signatureInfo.result.signatures;
93
+ // 4. submit transaction
94
+ let transactionInfo = yield sdk.transaction.submit({
95
+ blob,
96
+ signature: signature,
97
+ });
98
+
99
+ console.log(transactionInfo);
100
+
101
+ }).catch(err => {
102
+ console.log(err);
103
+ });
104
+ });
105
+
106
+ });
@@ -0,0 +1,101 @@
1
+ 'use strict';
2
+
3
+ require('chai').should();
4
+ const BigNumber = require('bignumber.js');
5
+ const co = require('co');
6
+
7
+ const OpenChainSDK = require('../index');
8
+
9
+ const sdk = new OpenChainSDK({
10
+ host: 'localhost/node/api',
11
+ // host: '192.168.1.34:36002',
12
+ });
13
+
14
+ describe('Test ctp10Token Transfer From Operation', function() {
15
+
16
+ it('Test ctp10Token Transfer From Operation', async() => {
17
+ const privateKey = 'private key';
18
+ let sourceAddress = 'adxScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3r';
19
+ const result = await sdk.account.getNonce(sourceAddress);
20
+
21
+ if (result.errorCode !== 0) {
22
+ console.log(result);
23
+ return;
24
+ }
25
+ let nonce = result.result.nonce;
26
+
27
+ nonce = new BigNumber(nonce).plus(1).toString(10);
28
+
29
+ let ctp10TokenTransferFromOperation = await sdk.operation.ctp10TokenTransferFromOperation({
30
+ contractAddress: 'adxSqKcX8wGCMKhzNUBoDWfbeQaMhfnGdtyG2',
31
+ destAddress: 'adxSqKcX8wGCMKhzNUBoDWfbeQaMhfnGdtyG2',
32
+ fromAddress: 'adxScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3r',
33
+ tokenAmount: '3',
34
+ sourceAddress,
35
+ // metadata: '',
36
+ });
37
+
38
+ if (ctp10TokenTransferFromOperation.errorCode !== 0) {
39
+ console.log(ctp10TokenTransferFromOperation);
40
+ return;
41
+ }
42
+
43
+ const operationItem = ctp10TokenTransferFromOperation.result.operation;
44
+
45
+ const args = {
46
+ sourceAddress,
47
+ nonce,
48
+ operations: [operationItem],
49
+ signtureNumber: '100',
50
+ // metadata: 'Test evaluation fee',
51
+ };
52
+
53
+ let feeData = await sdk.transaction.evaluateFee(args);
54
+ if (feeData.errorCode !== 0) {
55
+ console.log(feeData);
56
+ return;
57
+ }
58
+
59
+ // console.log(feeData);
60
+ // return;
61
+ let feeLimit = feeData.result.feeLimit;
62
+ let gasPrice = feeData.result.gasPrice;
63
+
64
+ // 2. build blob
65
+ let blobInfo = sdk.transaction.buildBlob({
66
+ sourceAddress: sourceAddress,
67
+ gasPrice,
68
+ feeLimit,
69
+ nonce: nonce,
70
+ operations: [ operationItem ],
71
+ });
72
+
73
+ if (blobInfo.errorCode !== 0) {
74
+ console.log(blobInfo);
75
+ return;
76
+ }
77
+
78
+ let blob = blobInfo.result.transactionBlob;
79
+
80
+ // 3. sign blob
81
+ let signatureInfo = sdk.transaction.sign({
82
+ privateKeys: [ privateKey ],
83
+ blob,
84
+ });
85
+
86
+ if (signatureInfo.errorCode !== 0) {
87
+ console.log(signatureInfo);
88
+ return;
89
+ }
90
+
91
+ let signature = signatureInfo.result.signatures;
92
+ // 4. submit transaction
93
+ let transactionInfo = await sdk.transaction.submit({
94
+ blob,
95
+ signature: signature,
96
+ });
97
+
98
+ console.log(transactionInfo);
99
+ });
100
+
101
+ });