Cupcakes SDK to allow developers access to Authentication & Smart Contract Wallets

Overview

Introduction

Cupcakes allow DAPPs developers access to Smart Contract Wallets. These wallets can be DAPPs specific or User specific. You must read about Wallets section before using the SDK.

:::caution

This SDK is a work in progress, in the meantime, feel free the to read the docs and give us your feedback on Telegram! ๐Ÿ’ฌ

:::

Getting Started

A guide for adding a Cupcakes SDK to your application & start bundling transactions. There are two parts of the documentation, bundling transaction and sponsoring gas.

For both of them you would need to install our SDK. For sponsoring gas, you will have to first create a paymaster contract. To know more about how to create a paymaster contract, read here.

What you'll need

  • Node.js version 16.14 or above:
    • When installing Node.js, you are recommended to check all checkboxes related to dependencies.

Installing SDK

Our SDK is currently under development, we will be hosting it on NPM soon. The Client SDK will be available in JavaScript with full TypeScript support.

:::caution

PackageName is still TBD and will be added here on release.

:::

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<Tabs>
<TabItem value="npm" label="npm" default>
npm install @cupcakes-sdk/scw
</TabItem>
<TabItem value="yarn" label="yarn" default>
yarn add @cupcakes-sdk/scw
</TabItem>
</Tabs>

Wallets

Smart Contract Wallets (SCW) allows DAPP developer to bundle multiple transaction & pay gas fees for their users. You must create a SCW using our SDK for every user. The final bundled call will initiate from user's SCW. If you want to transfer the final assets to the user's current EOA, then you MUST send the transaction to transfer the assets from SCW to EOA separately.

To know how to create a SCW for a user see Dapp specific wallets.


Dapp specific wallets

Install our SDK using instructions here.

Initiate a wallet

Create a Smart Contract Wallet for a user. You MUST pass a signer while creating the SCW. The signer will have the custody of the SCW.

import { Signer } from 'ethers'
import { SCWProvider } from '@cupcakes-sdk/scw'

/**
 * You can get signer using either the private key
 * const signer: Signer = new ether.Wallet(privateKey);
 * You can get signer if user has an EOA using wagmi.sh
 * const { data: signer } = useSigner();
 */

/* Once you have signer & provider, create user's SCW */

/**
 * @param provder - any BaseProvider from ethers (JSONRpcProvider | window.ethereum | etc)
 * @param signer - this will be the owner of the SCW that will be deployed.
 */
const scwProvider: SCWProvider = await SCWProvider.getSCWForOwner(provider, signer)

Once the SCW has been initiated, you can use it as a normal signer with ethers/web3/etc to connect & send bundled transactions.

Executing transactions

You can get Signer from the SCWProvider we created above & start using it normally as you would use an EOA.

const scwSigner = scwProvider.getSigner()
const greeter = new ethers.Contract(GREETER_ADDR, GreeterArtifact.abi, scwSigner)

const tx = await greeter.addGreet({
  value: ethers.utils.parseEther('0.0001'),
})
console.log(tx)

Bundling transactions

You can also send multiple transactions within a single transaction using SCW. Think of approvide ERC20 tokens & deposit them in a single transaction with a single signature from the users.

Read more about how here.

:::danger

The transactions sent using ethers/web3/etc won't be by default bundled or sponsored. Use sendTransactions instead to bundle transactions, see Bundle Transactions. If you want to sponer, make sure you connect a paymaster, see Gassless Experience

:::

:::info

Wallet is not deployed instantly, it will only be deployed once you do the first transaction, resulting in a higher gas fees in the first transaction. Though the scw address is deterministic and funds can be sent to the address.

:::

Bundle Transactions

Bundling transactions opens up a plathora of possibilities. We have listed a few of them as example:

  1. Users won't have to do two transactions for approving an ERC20 token & then depositing it.
  2. You can easily support depositing of any ERC20 in your app. Just add a transaction to swap user's token to your preffered token using any Dex.
  3. Modular Contract designs, deploy only specific contract modules and then join them off-chain using a bundler transactions.

Single chain bundling

You must have initialised iSDK & created a SCWProvider. We have exposed a function in a SCWSigner called sendTransactions using which you can send multiple transactions.

const scwSigner = scwProvider.getSigner()
const greeter = new ethers.Contract(GREETER_ADDR, GreeterArtifact.abi, scwSigner)

const transactionData = greeter.interface.encodeFunctionData('addGreet')

const tx = await scwProvider.sendTransactions([
  {
    to: GREETER_ADDR,
    value: ethers.utils.parseEther('0.0001'),
    data: transactionData,
  },
  {
    to: GREETER_ADDR,
    value: ethers.utils.parseEther('0.0002'),
    data: transactionData,
  },
])
console.log(tx)
await scwProvider.sendTransactions([
  {
    to: ERC20_TOKEN_ADDR,
    value: ethers.utils.parseEther('0.1'),
    data: TOKEN.interface.encodeFunctionData('approve', [
      spenderAddress,
      ethers.utils.parseEther(amount * 10), // getting approval from 10 times the amount to be spent
    ]),
  },
  {
    to: myContract.address,
    value: ethers.utils.parseEther('0.1'),
    data: myContract.interface.encodeFunctionData('stake', [ERC20_TOKEN_ADDR, ethers.utils.parseEther(amount)]),
  },
])

Cross chain bundling

:::info

Cross-chain Bundling will be coming soon, which will enable you to add bridging transactions to your transactions as well.

:::

Gassless Experience

Cupkaes SDK will enable conditional gassless experience, which includes partial gas-sponsoring. This enables you to have complex integrations like: sponsoring of gas on ethereum upto $5 and 100% on L2/sidechain.

Before you can start sponsoring gas, you must deploy a paymaster contract. The paymaster MUST be staked & should have enough deposit to sponsor for gas. If the deposited amount becomes lesser than the gas required then your transactions will start failing.


Paymaster

Paymaster is a contract that sponsors gas fees on behalf of users. To know more about how it works, read in the architecture section.

To enable gas sponsoring these are the steps you must do:

  1. Deploy a paymaster
  2. Stake paymaster
  3. Register a webhook
  4. Integrate with frontend

Deploy a paymaster

Head to our website https://comingsoon@cupcakes and follow the steps shown in the video below to deploy your first paymaster.

<iframe width="720" height="406" src="https://www.youtube-nocookie.com/embed/jreqzJMzR5s" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

Stake & deposit funds

Once you have created your paymaster, you will have to stake your funds. The Minimum stake as of now is x MATIC with a lock-in of 7 days. The stake is to make sure no fraudulant activity can be performed by the paymaster. The staked funds will be deductded if any such fraudulant activity is found.

:::caution You must have enough deposit left to cover for 100% of the gas fees even if you only want to sponsor a portion of it. If desposit is not enough, the transaction will be reverted. :::

Learn more about how your stake can be slashed more in detail here.

Register webhook

You will have to register a webhook, where we will be sending the a POST request to verify the sponsoring of the gas.

The requst will have the following body:

{
  "auth_code": "b110a339-ff6c-4456-8adb-b236a3da11d3",
  "timestamp": 1662805504483,
  "userOperation": {
    "sender": "0xadb2...asd4", // Sender's address of the SCW
    "maxGasCost": 123, // you can use this as the total of all the above gas breakup & use this to make decision of sponsoring
    "paymasterDeposit": 123, // the amount of deposit left in your paymaster contract, you can send refill transactions using this if you want to
    "paymasterAddress": "0x23rr...", // your paymaster contract address, you should send money to this address if paymasterDeposit is approaching zero
    "transactions": [
      // this is the array of transactions that your frontend SDK included for bundling
      {
        "to": "0x123..",
        "value": 4, // value in ethers
        "data": "0xadsf..." // call data your SDK passed
      }
    ],
    // The following fields are part of the UserOperation that will be used to generate signature, you can ignore these if you are using our paymaster SDK
    "nonce": 123,
    "initCode": "0xAxvd3r....adfsg4r", //init code, if not empty means that this wallet doesn't exist and will be deployed in this transaction along with executing the required transaction
    "callData": "0xsdfdasf...000", // call data of the execution
    "callGas": 123, // the amount of gas the main execution of transaction will take
    "verificationGas": 123, //the constant amount of gas which is required to verify sender's ownership
    "preVerificationGas": 123, // the constant amount of gas which is required by the bundler for processing the transaction
    "maxFeePerGas": 123, // the maximum gas price, this depends on how busy the network is
    "maxPriorityFeePerGas": 123 // the fee that will be used to tip the miner
  }
}

You must verify auth_code to check if the call is from our service or not. You will see the auth_code once you register a success webhook.

You must return with a 200 code if you agree to sponsor the transaction. If you choose not to sponsor, you must return with a 403 - Forbidden status code response.

Integrate with frontend

You will have to connect your paymaster with the SCW you created in Wallets section.

import { PaymasterAPI } from '@cupcakes-sdk/scw'

// You can get the your API KEY when you create a paymaster, every paymaster has a different API KEY

/* Connect to us to get Paymaster URL & Paymaster API KEY */
const paymasterAPI = new PaymasterAPI(process.env.REACT_APP_PAYMASTER_URL, process.env.REACT_APP_PAYMASTER_API_KEY)

/* Connect your paymaster to the provider */
scwProvider.connectPaymaster(paymasterAPI)

/* Do transaction as normal */
const scwSigner = scwProvider.getSigner()
const greeter = new ethers.Contract(GREETER_ADDR, GreeterArtifact.abi, scwSigner)

const tx = await greeter.addGreet({
  value: ethers.utils.parseEther('0.0001'),
})
console.log(tx)

/* Disconnect if you don't want to sponsor amny further */
scwProvider.disconnectPaymaster()

Overview

Smart Contract Wallet (SCW)

Each SCW has a signer assiciated with it,

SCW Architecture Basic

Bundling

SCW Architecture Bundled

Gassless Experience

SCW Architecture Paymaster

You might also like...

Ethereum smart contract gas cost waste pattern detection and patching tool

Ethereum smart contract gas cost waste pattern detection and patching tool

Ethereum smart contract gas cost waste pattern detection and patching tool

Mar 23, 2022

A simple multilateral escrow smart contract for ETH and ERC-20 tokens governed by Cobie.

A simple multilateral escrow smart contract for ETH and ERC-20 tokens governed by Cobie.

Multilateral Escrow Smart Contract Governed by Cobie Test Deployments Cobie's address: 0x4Cbe68d825d21cB4978F56815613eeD06Cf30152 Rinkeby: 0xFfE420602

Dec 15, 2022

This repository contains the Solidity smart contract of Enso, a detailed list of features and deployment instructions.

Enso NFT Smart Contract This repository contains the Solidity smart contract of Enso, a detailed list of features and deployment instructions. We stro

Apr 24, 2022

This is a development platform to quickly generate, develop & deploy smart contract based applications on StarkNet.

This is a development platform to quickly generate, develop & deploy smart contract based applications on StarkNet.

generator-starknet This is a development platform to quickly generate, develop, & deploy smart contract based apps on StarkNet. Installation First, in

Nov 18, 2022

Connect your Ethereum smart contract to any real world API using the oracle pattern!

Minimal Viable Oracle (MVO) - An effective way to Build your own oracle with Solidity Smart contracts cannot access off-chain data directly. This repo

Aug 25, 2022

In this repository, I try to perform a mainnet fork and then simulate popular smart contract exploits on various DEFI Protocols using Hardhat Framework.

defiHacks_via_Hardhat 1. Alchemix Access Control Bug Any user could have called setWhitelist() to give an attacker the ability to call the harvest fun

Dec 27, 2022

Pull a smart contract from mainnet onto your local chain.

hardhat-copy hardhat-copy helps you import an Ethereum mainnet smart contract onto your local Hardhat node, enabling you to rapidly experiment with pr

Aug 21, 2022

๐Ÿ”†๐Ÿ”Ž๐Ÿ‘€ Smart Contract Storage Viewer, DataType Guesser, Toolbox & Transaction Decoder

๐Ÿ”†๐Ÿ”Ž๐Ÿ‘€  Smart Contract Storage Viewer, DataType Guesser, Toolbox & Transaction Decoder

๐Ÿ”† ๐Ÿ”Ž ๐Ÿ‘€ Smart Contract Storage HexViewer Demo Target - the target contract API Endpoint - your infura (or equivalent) api key Retrieves smart contrac

Nov 27, 2022

A code formatter for the Motoko smart contract language.

Motoko Formatter ยท A Prettier plugin for the Motoko programming language. Setup After making sure Node.js is installed on your local machine, run the

Dec 19, 2022
Owner
null
We are creating a Library that would ensure developers do not reinvent the wheel anymore as far as Authentication is concerned. Developers can easily register and download authentication codes that suits their need at any point.

#AuthWiki Resource Product Documentation Figma Database Schema First Presentation Live Link API Documentation Individual Contributions User Activity U

Zuri Training 17 Dec 2, 2022
The iofod SDK provides developers with the ability to interact with the main iofod interface within the Web worker, enabling rapid development of iofod extensions through the SDK.

iofod-sdk English | ็ฎ€ไฝ“ไธญๆ–‡ The iofod SDK provides developers with the ability to interact with the main iofod interface within the Web worker, enabling

iofod, Inc. 47 Oct 17, 2022
๐Ÿฅ Batch contract/on-chain queries to the same block. Multicall SDK for the Klaytn blockchain.

Klaytn Multicall Built for inevitable-changes/bento Inspired by makerdao/multicall and dopex-io/web3-multicall ?? Installation # Yarn yarn install kla

Inevitable (Bento) 4 Nov 7, 2022
The Basement SDK has sensible defaults and flexibility to allow you to get the data you want efficiently and effortlessly.

Basement SDK The Basement SDK has sensible defaults and flexibility to allow you to get the data you want efficiently and effortlessly. Installation B

Basement for Developers 10 Dec 6, 2022
Movehat is a TypeScript SDK for Move on Sui built on top of Sui's TypeScript SDK and our fork of Ian Macalinao's `move-ts`.

Movehat Movehat is a TypeScript SDK for Move on Sui built on top of Sui's TypeScript SDK and our fork of Ian Macalinao's move-ts. Movehat aspires to b

Pentagon 10 Sep 30, 2022
First smart contract deployed on Rinkeby.

Inbox-Contract First smart contract deployed on Rinkeby. It has a basic constructor which accpets a string and assigns the string to the message varia

Stanley Moukhametzianov 1 Dec 26, 2021
Web3-citizens-app - React application based on smart contract using web3 and MetaMask extention.

Citizens App (web3-react-redux) React application based on smart contract using web3 and MetaMask extention. Start the applicarion Recomend to install

Denys Voloshyn 3 Aug 25, 2022
Aergo Timer Service schedule smart contract function calls

Aergo Timer Service โฐ Create timers to call functions on your smart contracts Schedule calls based on time interval or on specific date-times For a sm

aergo 3 Mar 10, 2022
Blockchain, Smart Contract, Ganache, Remix, Web3, Solidity, Java Script, MQTT, ESP32, RFID, DHT11,

Blockchain, Smart Contract, Ganache, Remix, Web3, Solidity, Java Script, MQTT, ESP32, RFID, DHT11,

Hajar OUAAROUCH 5 May 24, 2022
SmartBuilder: A Block-based Visual Programming Framework for Smart Contract Development

SmartBuilder A Block-based Visual Programming Framework for Smart Contract Development Technology stack used SmartBuilder Framework - Google Blockly A

ibelab 4 Mar 29, 2022