All Projects → OpenZeppelin → starter-kit-gsn

OpenZeppelin / starter-kit-gsn

Licence: MIT license
An OpenZeppelin starter kit focused on GSN.

Programming Languages

javascript
184084 projects - #8 most used programming language
CSS
56736 projects
solidity
1140 projects
HTML
75241 projects

Projects that are alternatives of or similar to starter-kit-gsn

Eth Crypto
Cryptographic javascript-functions for ethereum and tutorials to use them with web3js and solidity
Stars: ✭ 420 (+976.92%)
Mutual labels:  dapp, smart-contracts, truffle, web3
Eth.social
An Ethereum dApp for posting social events.
Stars: ✭ 17 (-56.41%)
Mutual labels:  dapp, smart-contracts, truffle, web3
openzeppelin-network.js
An easy to use and reliable library that provides one line access to Web3 API.
Stars: ✭ 45 (+15.38%)
Mutual labels:  dapp, web3, metamask, infura
eth-decoder
Simple library to decode ethereum transaction and logs
Stars: ✭ 32 (-17.95%)
Mutual labels:  smart-contracts, truffle, web3
create-truffle-dapp
Create and deploy Truffle projects with no configuration.
Stars: ✭ 17 (-56.41%)
Mutual labels:  dapp, smart-contracts, truffle
awesome-waves
Curated list of awesome things for development on Waves blockchain.
Stars: ✭ 60 (+53.85%)
Mutual labels:  dapp, smart-contracts, web3
go-ethutil
Ethereum utility functions for Go.
Stars: ✭ 17 (-56.41%)
Mutual labels:  dapp, smart-contracts, web3
trufflepig
🍄🐷Truffle contract artifact loading tool for local development
Stars: ✭ 45 (+15.38%)
Mutual labels:  smart-contracts, truffle, web3
Angular Truffle Dapp
Angular + Truffle = Beautiful Material Dapp that can be scaled
Stars: ✭ 12 (-69.23%)
Mutual labels:  dapp, truffle, web3
NFT-Dapp-Boilerplate
A highly scalable NFT and DEFI boilerplate with pre added web3 and different wallets with a focus on performance and best practices
Stars: ✭ 51 (+30.77%)
Mutual labels:  dapp, web3, metamask
Eth Vue
Featured in Awesome Vue [https://github.com/vuejs/awesome-vue], a curated list maintained by vuejs of awesome things related to the Vue.js framework, and Awesome List [https://awesomelists.net/150-Vue.js/3863-Open+Source/18749-DOkwufulueze-eth-vue], this Truffle Box provides everything you need to quickly build Ethereum dApps that have authentication features with vue, including configuration for easy deployment to the Ropsten Network. It's also Gravatar-enabled. Connecting to a running Ganache blockchain network from Truffle is also possible -- for fast development and testing purposes. Built on Truffle 5 and Vue 3, eth-vue uses vuex for state management, vuex-persist for local storage of app state, and vue-router for routing. Authentication functionalities are handled by Smart Contracts running on the Ethereum blockchain.
Stars: ✭ 171 (+338.46%)
Mutual labels:  dapp, truffle, web3
Love Ethereum
区块链学习
Stars: ✭ 323 (+728.21%)
Mutual labels:  dapp, smart-contracts, truffle
full-blockchain-solidity-course-py
Ultimate Solidity, Blockchain, and Smart Contract - Beginner to Expert Full Course | Python Edition
Stars: ✭ 5,349 (+13615.38%)
Mutual labels:  dapp, smart-contracts, web3
Web3 Vs Ethers
A basic cheatsheet of Web3.js vs Ethers (along w/ example apps!)
Stars: ✭ 103 (+164.1%)
Mutual labels:  dapp, truffle, web3
Erc20 Generator
Create an ERC20 Token for FREE in less than a minute with the most used Smart Contract Generator for ERC20 Token. No login. No setup. No coding required.
Stars: ✭ 202 (+417.95%)
Mutual labels:  dapp, smart-contracts, truffle
Trace
Supply chain transparency platform proof-of-concept based on the Ethereum blockchain ✍️
Stars: ✭ 52 (+33.33%)
Mutual labels:  dapp, truffle, web3
react-truffle-metamask
Build an DApp using react, redux, saga, truffle, metamask
Stars: ✭ 25 (-35.9%)
Mutual labels:  smart-contracts, truffle, metamask
nifty-game
🃏🎮A NFT(ERC721) card game build on Ethereum, Truffle, Ganache and hosting on IPFS.
Stars: ✭ 222 (+469.23%)
Mutual labels:  dapp, smart-contracts, truffle
ar-nft
👾 A React Native app to visualize your NFTs in AR
Stars: ✭ 71 (+82.05%)
Mutual labels:  dapp, web3, metamask
Starter Kit
An OpenZeppelin starter kit containing React, OpenZeppelin SDK & OpenZeppelin Contracts.
Stars: ✭ 101 (+158.97%)
Mutual labels:  dapp, truffle, web3

⚠️ This project is deprecated. We are no longer actively developing new features nor addressing issues. Read here for more info, and reach out if you are interested in taking over maintenance. We suggest looking into create-eth-app for a popular alternative to this project.

OpenZeppelin GSN Starter Kit

An OpenZeppelin Starter Kit GSN containing React, OpenZeppelin CLI, OpenZeppelin Contracts, Gas Station Network, Truffle and Infura.

OpenZeppelin GSN Starter Kit comes with everything you need to start using Gas Station Network contracts inside your applications. It also includes all the GSN Providers & Web3 connectors that you need to abstract gas for your users.

In addition to the contents included in the vanilla Starter Kit, this kit contains a step-by-step tutorial on how to enable Gas Station Network for a simple Counter Contract.

Requirements

Install Ganache, and Truffle

Installation

Ensure you are in a new and empty directory, and run the unpack command with gsn to create a starter project:

npx @openzeppelin/cli unpack gsn

Run

In a new terminal window, run your local blockchain:

ganache-cli --deterministic

In your original terminal window, at the top level of your folder, initialize the project and follow the prompts:

npx openzeppelin init

In a new terminal window, in the client directory, run the React app:

cd client
npm run start

Follow the instructions in the browser.

Test

Truffle can run tests written in Solidity or JavaScript against your smart contracts. Note the command varies slightly if you're in or outside of the truffle development console.

// inside the development console.
test

// outside the development console..
truffle test

Jest is included for testing React components. Compile your contracts before running Jest, or you may receive some file not found errors.

// ensure you are inside the client directory when running this
npm run test

Build

To build the application for production, use the build script. A production build will be in the client/build folder.

// ensure you are inside the client directory when running this
npm run build

Why this kit?

This kit leverages GSN to create dapps that are ready for mass adoption. Free your users from the initial burden of installing Metamask and obtaining Ether. Create blockchain applications that are indistinguishable from Web2.0 apps.

This documents assumes familiarity with the Gas Station Network. Check out our GSN getting started guide and GSN Kit Tutorial to learn more.

How does it use Web3 with GSN?

This kit uses Open Zeppelin network.js to create the connection to Web3. Using a couple of flags for development and production you can see how the dapp obtains a context that is aware of Gas Station Network.

// get GSN web3
const context = useWeb3Network("http://127.0.0.1:8545", {
  gsn: { dev: true }
});

How are the contracts modified to use GSN?

The Counter contract is modified to inherit from RelayRecipient. Also, the Counter contract is going to naively pay for all the transactions that are submitted. Note how the acceptRelayedCall determines this by returning 0. Also _preRelayedCall and _postRelayedCall methods must be implemented because they are defined as abstract in GSNRecipient.

pragma solidity ^0.5.0;

import "@openzeppelin/contracts-ethereum-package/contracts/GSN/GSNRecipient.sol";
import "@openzeppelin/upgrades/contracts/Initializable.sol";

contract Counter is Initializable, GSNRecipient {
  //it keeps a count to demonstrate stage changes
  uint private count;
  address private _owner;

  function initialize(uint num) public initializer {
    GSNRecipient.initialize();
    _owner = _msgSender();
    count = num;
  }

// accept all requests
  function acceptRelayedCall(
    address,
    address,
    bytes calldata,
    uint256,
    uint256,
    uint256,
    uint256,
    bytes calldata,
    uint256
    ) external view returns (uint256, bytes memory) {
    return _approveRelayedCall();
  }  ...
}

  function _preRelayedCall(bytes memory context) internal returns (bytes32) {
      // solhint-disable-previous-line no-empty-blocks
  }

  function _postRelayedCall(bytes memory context, bool, uint256 actualCharge, bytes32) internal {
      // solhint-disable-previous-line no-empty-blocks
  }

How to know if my recipient has funds?

The frontend also has some functions to help you see how much remaining balance you have left. Once it runs out, transactions will stop working because your dapp won't be able to pay the gas fee on behalf of its users.

const getDeploymentAndFunds = async () => {
  if (instance) {
    const isDeployed = await isRelayHubDeployedForRecipient(lib, _address);
    setIsDeployed(isDeployed);
    if (isDeployed) {
      const funds = await getRecipientFunds(lib, _address);
      setFunds(funds);
    }
  }
};

You can top your balance by sending funds to your contract using npx oz-gsn fund-recipient --recipient ADDRESS command or heading to the dapp tool.

How is the RelayHub deployed locally?

When you run npx oz-gsn fund-recipient, the following code gets executed:

// Ensure relayHub is deployed on the local network
if (options.relayHubAddress.toLowerCase() === data.relayHub.address.toLowerCase()) {
  await deployRelayHub(web3, options.from);
}

Note that on both mainnet and testnets, as well as local blockchain (ganache) environments, the address of the RelayHub contract is always 0xD216153c06E857cD7f72665E0aF1d7D82172F494.

FAQ

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].