starknet-react icon indicating copy to clipboard operation
starknet-react copied to clipboard

Introduce hooks for low-level contract calls and invocations

Open Pet3ris opened this issue 2 years ago • 2 comments

There are some use cases which may mandate using the low-level starknet.js operations callContract and invokeFunction. However, today, no hook api exists for them. This is particularly useful in StarkNet where we don't need the full contract signature to call a function.

Examples:

  • Rapid prototyping (e.g., only need to call 1 function without providing abi)
  • Low-level interactions (e.g., trading/MEV contracts in ethereum mainnet)
  • Security testing of contracts

Pet3ris avatar May 09 '22 11:05 Pet3ris

Agree with this. We should add the following hooks:

  • useProviderCall that has the same behaviour as the current call hook, but calls provider.callContract
  • useProviderInvoke that uses provider.invokeFunction

fracek avatar May 09 '22 11:05 fracek

Another way to do this, change useStarknetCall to:

function useStarknetCall({ contractOrAddress }: { contractOrAddress?: string | Contract })

If it's a Contract, then the behaviour is the same as today. If it's a string, then it uses callContract.

For invoke, I think using useStarknetExecute is enough?

fracek avatar Oct 01 '22 10:10 fracek

Is it still open ? I would like to work on this one if possible

J4ckyLIM avatar Jan 03 '23 13:01 J4ckyLIM

Someone else is working on this as part of moving everything to a wagmi-like API.

fracek avatar Jan 03 '23 14:01 fracek

This is now the default behaviour thanks to starknet.js populateTransaction.

fracek avatar Nov 20 '23 11:11 fracek