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
feat: Generate typescript clients automagically! #97
Conversation
src/commands/new.ts
Outdated
@@ -78,7 +80,7 @@ export default class New extends Command { | |||
cli.action.start('- frontend'); | |||
if (flags.framework === 'react') { | |||
await TemplateScaffolding.from({ | |||
remoteUrl: 'https://codeload.github.com/terra-money/terrain-frontend-template/zip/refs/heads/main', | |||
remoteUrl: 'https://codeload.github.com/octalmage/terrain-frontend-template/zip/refs/heads/main', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't forget to set this back!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found 99 potential problems in the proposed changes. Check the Files changed tab for more details.
When reviewing I'd recommend starting here: https://github.com/terra-money/terrain/pull/97/files#diff-c189f236d6e2a2b55daa0229225e3283b0d61abd993ae3aecad63bbb5ba9a885 Ignore the packages directory as much as possible, there's a lot of boilerplate in there. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found 99 potential problems in the proposed changes. Check the Files changed tab for more details.
import TerrainCLI from '../../TerrainCLI'; | ||
import generateClient from '../../lib/generateClient'; | ||
|
||
export default class GenerateClient extends Command { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good name! What do you think about having a generate folder with client (or types) as it's own entry point? To have a syntax like terrain contract:generate:client party
instead of terrain contract:generateClient party
.
If we apply this suggestion I will create an issue to also modify terrain contract:updateAdmin
Cool feature! Looking forward to use it in my projects! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found 99 potential problems in the proposed changes. Check the Files changed tab for more details.
Apologies for this giant PR, it seems larger than it really is since I'm including a couple of modified npm packages.
This PR adds a new command,
terrain contract:generateClient [contract name]
. When you run this command Terrain will generate a wallet provider and Terra.js compatible library you can import into automation scripts, tests, or your frontend to interact with your smart contracts.Lets say you have a smart contract named "party", to generate the client you will run:
This will output
PartyClient.ts
in./lib/clients/PartyClient.ts
.Using the generated client is easy. Import it where you'd like to call your smart contract, instantiate it will a few parameters, then start calling methods or queries exposed by the smart contract:
Generated clients accept a configured LCDClient, a Wallet instance, and the address to the deployed contract.