-
Notifications
You must be signed in to change notification settings - Fork 17
SIP-36: enabling eth_sendTransaction from within Snaps #180
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
Open
smilingkylan
wants to merge
2
commits into
main
Choose a base branch
from
kylan/eth_sendTransaction
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| --- | ||
| sip: 36 | ||
| title: Snap Transaction Creation with `eth_sendTransaction` | ||
| status: Draft | ||
| author: Kylan Hurt (@smilingkylan, kylan.hurt@consensys.net, kylan.hurt@gmail.com) | ||
| created: 2025-10-27 | ||
| --- | ||
|
|
||
| ## Abstract | ||
|
|
||
| The purpose of this SIP is to streamline the user experience by allowing Snaps to send transactions to the wallet provider directly with `eth_sendTransaction`, rather than requiring transactions to originate from outside of the Snap. Given that the user has already consented to the Snaps installation / functionality and each transaction is reviewed before the user approves it, this could be a great value-added feature. | ||
|
|
||
| ## Motivation | ||
|
|
||
| While writing a Snap that shows `onTransaction` insights there may be times when the user or app developer would like the user to take action in the form of an additional transaction. For example a Snap could prompt a user: | ||
|
|
||
| - to adjust permissions before sending a transaction | ||
| - to remove a risky delegation when a Snap's Transaction Insight alerts the user | ||
| - to add more funds to "current" address before attempting a large transaction | ||
| - to convert their currency to the correct form (eg ETH vs wETH) | ||
| - to set ENS Reverse Record or Domain Link before broadcasting transaction | ||
| - to reduce size of trade if Snap analysis feels it will cause too much slippage | ||
|
|
||
| As a sidenote this feature can become even more potent if used with SIP-35's `onActivityItem` lifecycle event, making it easier for a user to submit follow-up transactions once the original transaction has been submitted. For example it could encourage a user to buy more crypto, to re-send the transcaction with a better fee value, or submit attestations about a recipient or smart contract. | ||
|
|
||
| ## Specification | ||
|
|
||
| Snap developer will have to explicitly request the permission: | ||
|
|
||
| ```json | ||
| { | ||
| "initialPermissions": { | ||
| "endowment:ethereum-provider": {}, | ||
| "endowment:eth_sendTransaction": {} // the exact permission key can be decided by the Snaps dev team | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ```jsx | ||
| import { OnUserInputHandler } from '@metamask/snaps-sdk'; | ||
| import type { OnTransactionHandler } from "@metamask/snaps-sdk"; | ||
| import { Box, Heading, Text, Button } from "@metamask/snaps-sdk/jsx"; | ||
|
|
||
| export const onTransaction: OnTransactionHandler = async ({ | ||
| transaction, | ||
| chainId, | ||
| }) => { | ||
| const recipientAddress = transaction.to; | ||
| const reputationData = await fetchReputation(recipientAddress); | ||
|
|
||
| const onUserInput: OnUserInputHandler = async (props: OnUserInputProps) => { | ||
| const [type, direction] = props.event.name.split('_'); | ||
|
|
||
| if (!renderFn) return; | ||
| await ethereum.request({ | ||
| method: "eth_sendTransaction", // <---------- | ||
| params: [ | ||
| { | ||
| from: yourAddr, | ||
| to: smartContractAddress, | ||
| data: direction, | ||
| value: someValue, | ||
| // ... | ||
| } | ||
| ] | ||
| }); | ||
| } | ||
|
|
||
| return { | ||
| content: ( | ||
| <Box> | ||
| <Heading>Address Reputation</Heading> | ||
| <Text>Trusted by: {reputationData.trustedCount} users</Text> | ||
| <Text>Flagged by: {reputationData.flaggedCount} users</Text> | ||
|
|
||
| <Button name="attest_trusted"> | ||
| Rate as Trusted ✅ | ||
| </Button> | ||
| <Button name="attest_suspicious"> | ||
| Report as Suspicious ⚠️ | ||
| </Button> | ||
| </Box> | ||
| ), | ||
| }; | ||
| }; | ||
| ``` | ||
|
|
||
|
|
||
| ### Language | ||
|
|
||
| The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", | ||
| "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and | ||
| "OPTIONAL" written in uppercase in this document are to be interpreted as described in [RFC 2119](https://www.ietf.org/rfc/rfc2119.txt) | ||
|
|
||
| ### Snap Manifest | ||
|
|
||
| Already mentioned above | ||
|
|
||
| ### Security Considerations | ||
|
|
||
| Since `eth_sendTransaction` is a powerful command, some adjustments to UI / UX may be necessary to make sure the user understands that a new transaction is beign presented to them for signing. This can be especially tricky because smart contract function names and data are often presented as hex. | ||
|
|
||
| ### User Experience Considerations | ||
|
|
||
| Mostly making sure the presentation of a new transaction to the user does not disrupt existing pending transaction queue. In fact this `eth_sendTransaction` functionality may be best presented at moments that are *not* part of the transaction signing + broadcasting process | ||
|
|
||
| ## Backwards Compatibility | ||
|
|
||
| This SIP introduces a new method and does not modify any existing functionality. Therefore, there are no backwards compatibility concerns. | ||
|
|
||
| ## Copyright | ||
|
|
||
| Copyright and related rights waived via [CC0](../LICENSE). | ||
Oops, something went wrong.
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.
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.
The
eth_sendTransactionAPI is now available usingendowment:multichain-provider. Perhaps that removes the need for this SIP?