-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathfrom-submitted-request.ts
56 lines (42 loc) · 1.57 KB
/
from-submitted-request.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import {
Provider,
ScriptTransactionRequest,
TransactionResponse,
Wallet,
} from 'fuels';
import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env';
import { ScriptSum } from '../../../../typegend';
const provider = await Provider.create(LOCAL_NETWORK_URL);
const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider);
// #region transaction-response-2
/**
* Instantiate the transaction request using a ScriptTransactionRequest and
* set the script main function arguments
*/
const transactionRequest = new ScriptTransactionRequest({
script: ScriptSum.bytecode,
});
const scriptMainFunctionArguments = [1];
transactionRequest.setData(ScriptSum.abi, scriptMainFunctionArguments);
// Fund the transaction
await transactionRequest.autoCost(wallet);
// Submit the transaction
const response = await wallet.sendTransaction(transactionRequest);
// Generate the transaction summary
const transactionSummary = await response.getTransactionSummary();
// #endregion transaction-response-2
console.log('transactionSummary', transactionSummary);
const previouslySubmittedTransactionId = response.id;
// #region transaction-response-3
// Take a transaction ID from a previous transaction
const transactionId = previouslySubmittedTransactionId;
// 0x...
// Retrieve the transaction response from the transaction ID
const transactionResponse = await TransactionResponse.create(
transactionId,
provider
);
// Generate the transaction summary
const summary = await transactionResponse.getTransactionSummary();
// #endregion transaction-response-3
console.log('summary', summary);