-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_contract_exist.js
More file actions
38 lines (34 loc) · 1.05 KB
/
Copy pathtest_contract_exist.js
File metadata and controls
38 lines (34 loc) · 1.05 KB
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
const { rpc, TransactionBuilder, Account, Networks, Operation } = require('stellar-sdk');
const sorobanRpcUrl = 'https://mainnet.sorobanrpc.com';
const rpcServer = new rpc.Server(sorobanRpcUrl);
const agentWalletId = 'CBRPSAFRX2JAXLF3CYTQCETJRQAYCKCBBR24O4UVUVLF3X6Q4D7KVQSZ';
async function main() {
const tx = new TransactionBuilder(
new Account('GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF', '0'),
{
fee: '100',
networkPassphrase: Networks.PUBLIC,
}
)
.addOperation(
Operation.invokeContractFunction({
contract: agentWalletId,
function: 'state',
args: [],
})
)
.setTimeout(30)
.build();
try {
const sim = await rpcServer.simulateTransaction(tx);
console.log('Simulation success:', rpc.Api.isSimulationSuccess(sim));
if (rpc.Api.isSimulationSuccess(sim)) {
console.log('Return value:', sim.result.retval);
} else {
console.log('Error details:', sim.error);
}
} catch (e) {
console.error('RPC Error:', e);
}
}
main().catch(console.error);