fix(contract-client): allow undefined publicKey #941
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before ContractClient lived in stellar-sdk, we allowed (the equivalent of [1]) setting
publicKey
toundefined
.This is handy, if you're trying to get the result of view calls and you only need the simulation. Our main onboarding tutorial assumes that we have this functionality, and it definitely makes for a more incremental build-up of mental models about how Soroban and Stellar work.
While making ContractClient, we thought maybe this added unnecessary complexity to the interface, and further thought people would be able to pass
Keypair.random()
if they wanted a fake account.The trouble with the
Keypair.random()
approach is that the call toserver.getAccount
fails, because the account has not been funded.We could fix this by doing:
But this seems clumsy. Even if there's a better way to check that the caught error is the error we expect (
{ code: 404, message: 'Account not found' }
), why allow passing a publicKey if it's actually ignored? It seems like a clearer expression of intent to allow the publicKey to beundefined
.