GithubHelp home page GithubHelp logo

mollybeach / erc-4337-account-abstraction-contracts Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 4.0 92 KB

Account Abstraction aims to eliminate distinction between EOAs & CAs by unifying them in single contract account transact with tokens & create contracts, unifying both acc types. ERC-4337 has smart contract functionality & provides improved authentication methods, automatic payments, gas optimization, account recovery, cross-chain interoperability

License: MIT License

TypeScript 85.78% JavaScript 14.22%
custom-authentication erc-4337 open-zeppelin solidity

erc-4337-account-abstraction-contracts's Introduction

Getting started

A collection of example scripts for working with ERC-4337. For an overview on the EIP and account abstraction, see our docs here.

All scripts in this repository is built using @account-abstraction/sdk. The implementation of all the following commands are located in the scripts directory.

Table of contents

Setup

Clone this repo into your local environment:

git clone [email protected]:stackup-wallet/erc-4337-examples.git

Install dependencies:

yarn install

Init config

These config values will be used for all documented commands.

yarn run init

bundlerUrl

Default value is set to http://localhost:4337.

All UserOperations are required to be sent to a bundler. This field specifies the URL for the bundler you want to use.

You can run a self-hosted instance with stackup-bundler. Fully managed instances are also available. If you would like one setup, come talk to us!

rpcUrl

Default value is set to http://localhost:8545.

This is a standard RPC URL for an ethereum node. By default it uses the public RPC for Polygon mumbai testnet. You can change this to any network you like.

signingKey

Default value is randomly generated with ethers.js.

All UserOperations have a signature field which smart contract accounts will use to validate transactions. This key will be used to sign all UserOperations and set as the owner for the smart contract account.

entryPoint

Default value is set to 0x0576a174D229E3cFA37253523E645A78A0C91B57.

This is address of the singleton EntryPoint contract. It is the same on all networks.

simpleAccountFactory

Default value is set to 0x71D63edCdA95C61D6235552b5Bc74E32d8e2527B.

This is the factory address for deploying SimpleAccount.sol. It is the same on all networks and allows us to generate deterministic addresses.

The default factory deploys a forked version of SimpleAccount.sol with a one line change to make calling batched transactions easier.

paymasterUrl

Default value is an empty string.

This field specifies the URL to request paymaster approval when using the --withPaymaster flag. The examples assume that any paymaster service follows the interface specified here.

Commands

Once you have an environment setup, these commands can be used for running the example scripts.

The location of each script mimics the command structure. For example yarn run simpleAccount address will be located in scripts/simpleAccount/address.ts

Optional flags

All commands below can be augmented with the following flags.

With Paymaster

Appending --withPaymaster to any command will send UserOperations to the paymasterUrl specified in the config for approval. If successful, gas for this transaction will be paid for by the paymaster.

Example:

yarn run simpleAccount:erc20Transfer --withPaymaster ...

In this example, the contract account does not need to hold any ETH for gas fees.


Simple Account

Scripts for managing accounts based on SimpleAccount.sol.

For CLI details:

yarn run simpleAccount -h

Get account address

Smart contract account addresses can be deterministically generated. Use this command to get your account address based on the signingKey set in your config.json.

The account will be automatically deployed on the first transaction.

yarn run simpleAccount address

Transfer ETH

Before executing a transfer, make sure to deposit some ETH to the address generated by the simpleAccount address command.

yarn run simpleAccount transfer --to <address> --amount <eth>

Transfer ERC-20 token

Make sure the address generated by simpleAccount:address has enough specified tokens to execute the transfer.

If not using a paymaster, make sure to also have enough ETH to pay gas fees.

yarn run simpleAccount erc20Transfer --token <address> --to <address> --amount <decimal>

Batch transfer ETH

This example shows how we can do multiple atomic ETH transfers in a single transaction.

# recipient addresses is comma separated.
# e.g. 0x123..abc,0x456...def
yarn run simpleAccount batchTransfer --to <addresses> --amount <eth>

Batch transfer ERC-20 token

Similar to simpleAccount batchTransfer, we can also do multiple atomic contract interactions in a single transaction. This example shows us how with an ERC-20 token.

# recipient addresses is comma separated.
# e.g. 0x123..abc,0x456...def
yarn run simpleAccount batchErc20Transfer --token <address> --to <addresses> --amount <decimal>

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Feel free to direct any technical related questions to the dev-hub channel in the Stackup Discord.

erc-4337-account-abstraction-contracts's People

Contributors

hazim-j avatar rewnad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.