Generate local contract ABI JSON
Is your feature request related to a problem? Please describe.
I need a way to get the contract ABI before being deployed to a node. Once it's deployed, one can query the API to get the JSON but there is no way to do it for local contracts at the moment.
Describe the solution you'd like
A clarity cli command to generate the JSON of a contract or smth similar.
Hey Léo 👋
You could achieve that with a JS script and the SDK (simnet.getContractsInterfaces()), that's a bit limited but might work for you.
Otherwise, a CLI command or something similar would be super useful. I'm thinking about something like that, a part of the TS client codegen, that could expose a standard JSON schema as well
Could you provide more details about your needs and use case? That would help us prioritize
@hugo-stacks I created https://github.com/pradel/clarity-abitype to help clarity tooling typechecking based on a provided ABI, I wanted to play with how this could work with clarinet / stacks.js to greatly improve the DX and get proper autocomplete and type checking while developing.
Indeed, I would approach this with Clarinet, which can get the interface of any contract, especially local ones.
How does clarity-abitype compete with clarigen?
There is no to set up a build process to generate types like clarigen, you just provide the ABI of your contract, and it's working out of the box.
It could also be used to improve the DX of clarinet (and stacks.js in the same way) in general and remove the need to cast the value to clarity types manually. Eg:
const result = simnet.callReadOnlyFn(
// Add the abi
myContractAbi,
'pool',
// This param is typechecked (so you get build error if it doesn't exist in your clarity file)
'get-contribution-amount',
// This param is typechecked (so you get build error if it doesn't exist in your clarity file)
// Idea for inprovement as we have the ABI JSON we know what clarity type is expected so we can encode in the background and do
// before [Cl.standardPrincipal(wallet)],
// Typescript expect a string or string.string type and will throw and error if you pass smth else
[wallet],
wallet
);