Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: some signing and simulate issues #346

Merged
merged 3 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 53 additions & 6 deletions docs/capabilities/transaction-composer.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,57 @@ The [methods to construct a transaction](../code/classes/types_composer.default.
For example:

```typescript
const result = algorand.addPayment({ sender: 'SENDER', receiver: 'RECEIVER', amount: (100).microAlgo() }).addAppCallMethodCall({
sender: 'SENDER',
appId: 123n,
method: abiMethod,
args: [1, 2, 3],
}).
const result = algorand
.newGroup()
.addPayment({ sender: 'SENDER', receiver: 'RECEIVER', amount: (100).microAlgo() })
.addAppCallMethodCall({
sender: 'SENDER',
appId: 123n,
method: abiMethod,
args: [1, 2, 3],
})
```

## Simulating a transaction

Transactions can be simulated using the simulate endpoint in algod, which enables evaluating the transaction on the network without it actually being commited to a block.
This is a powerful feature, which has a number of options which are detailed in the [simulate API docs](https://developer.algorand.org/docs/rest-apis/algod/#post-v2transactionssimulate).

For example you can simulate a transaction group like below:

```typescript
const result = await algorand
.newGroup()
.addPayment({ sender: 'SENDER', receiver: 'RECEIVER', amount: (100).microAlgo() })
.addAppCallMethodCall({
sender: 'SENDER',
appId: 123n,
method: abiMethod,
args: [1, 2, 3],
})
.simulate()
```

The above will execute a simulate request asserting that all transactions in the group are correctly signed.

### Simulate without signing

There are situations where you may not be able to (or want to) sign the transactions when executing simulate.
In these instances you should set `skipSignatures: true` which automatically builds empty transaction signers and sets both `fix-signers` and `allow-empty-signatures` to `true` when sending the algod API call.

For example:

```typescript
const result = await algorand
.newGroup()
.addPayment({ sender: 'SENDER', receiver: 'RECEIVER', amount: (100).microAlgo() })
.addAppCallMethodCall({
sender: 'SENDER',
appId: 123n,
method: abiMethod,
args: [1, 2, 3],
})
.simulate({
skipSignatures: true,
})
```
2 changes: 1 addition & 1 deletion docs/code/classes/types_app_client.AppClient.md
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ ___
▸ **getSigner**(`sender`, `signer`): `undefined` \| `TransactionSigner` \| [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md)

Returns the signer for a call, using the provided signer or the `defaultSigner`
if no signer was provided and the call will use default sender
if no signer was provided and the sender resolves to the default sender, the call will use default signer
or `undefined` otherwise (so the signer is resolved from `AlgorandClient`)

#### Parameters
Expand Down
146 changes: 86 additions & 60 deletions docs/code/classes/types_app_factory.AppFactory.md

Large diffs are not rendered by default.

Loading
Loading