Skip to content

Commit

Permalink
Merge pull request ethereum#1 from danfinlay/add-7710-example-to-7715
Browse files Browse the repository at this point in the history
Add erc-7710 example
  • Loading branch information
pedrouid authored May 26, 2024
2 parents 9b592d2 + f630c7a commit 0886b2c
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion ERCS/erc-7715.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,62 @@ sequenceDiagram

#### ERC-7710

TODO
When requesting permissions with a `type` of `account`, the returned data will be redeemable using the interfaces specified in ERC-7710. This allows the recipient of the permissions to use any account type (EOA or contract) to form a transaction or UserOp using whatever payment or relay infrastructure they prefer, by sending an internal message to the returned `permissions.signerData.submitToAddress` and calling its `function redeemDelegation(bytes calldata _data, Action calldata _action) external;` function with the `_data` parameter set to the returned `permissions.permissionsContext`, and the `_action` data forming the message that the permissions recipient desires the user's account to emit, as defined by this struct:

```
struct Action {
address to;
uint256 value;
bytes data;
}
```

A simple pseudocode example of using a permission in this way, given two ethers signers in the same context, where `alice` wants to request a permission from `bob` might be like this:

```
// Alice requests a permission from Bob
const permissionsResponse = await bob.request({
method: 'wallet_issuePermissions',
params: [{
signer: {
type: 'account',
data: {
id: bob.address
}
},
permissions: [{
type: 'native-token-limit',
data: {
amount: ethers.utils.parseEther('1.0')
},
required: true
}],
expiry: Math.floor(Date.now() / 1000) + 3600 // 1 hour from now
}]
});
// Extract the permissionsContext and submitToAddress
const permissionsContext = permissionsResponse.permissionsContext;
const submitToAddress = permissionsResponse.signerData.submitToAddress;
// Alice forms the action she wants Bob's account to take
const action = {
to: alice.address,
value: ethers.utils.parseEther('0.5'),
data: '0x'
};
// Alice sends the transaction by calling redeemDelegation on Bob's account
const tx = await bob.sendTransaction({
to: submitToAddress,
data: bob.interface.encodeFunctionData('redeemDelegation', [
permissionsContext,
action
])
});
await tx.wait();
```

## Rationale

Expand Down

0 comments on commit 0886b2c

Please sign in to comment.