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

feat: add execute hook for multicall #143

Closed
wants to merge 7 commits into from

Conversation

starknetdev
Copy link
Contributor

Based on the discussions that have happened in #102 I have created a useStarknetExecute hook enabling multicalls.

Calls need to be defined when creating the hook, and not on submit. Similar to how useSignTypedData is done.

const { data, loading, error, reset, execute } = useStarknetExecute({
  calls,
  metadata
})

Currently formatting the calldata in calls is up to the UI to implement. I have made an example in next react app that does this. This is an example of an approval and deposit made to a bank contract.

The calls are also not currently view exposed for a 'tx cart' yet, this would be up to the UI to handle separately. Although definitely would want to try implement in the future.

  • pnpm changeset
  • pnpm lint

@fracek
Copy link
Contributor

fracek commented Jul 15, 2022

I like this interface (and now i think invoke should also have the function args as arguments to the hook).

{
contractAddress: tokenAddress,
entrypoint: 'approve',
calldata: [toBN(bankAddress).toString(), amount, '0'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is because the amount is an uint256? Should work with toBN(amount) instead of amount, '0'.

Copy link
Contributor Author

@starknetdev starknetdev Jul 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With toBN(amount) it passes as is (the object) in the transaction. The transaction goes through but no tokens are approved or sent (in example).The transaction log (in Argent for example) looks like this:

Transaction data
[
  "688466037836324210640682130671894602364182264487879175191481661276184612058",
  {
    "negative": 0,
    "words": [
      1
    ],
    "length": 1,
    "red": null
  },
  {
    "negative": 0,
    "words": [
      1
    ],
    "length": 1,
    "red": null
  }
]

@fracek
Copy link
Contributor

fracek commented Jul 15, 2022

Added a minor comment about the example.

Should also add a documentation page.

@starknetdev
Copy link
Contributor Author

Fixed minor react-next export issue and added docs on execute hook

@fracek fracek marked this pull request as ready for review July 25, 2022 15:41
@fracek
Copy link
Contributor

fracek commented Jul 25, 2022

Continue in #145. As we discussed on discord, need to publish the package before we can add an example using it.

@fracek fracek closed this Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants