पैकेज, रिपॉज़िटरी और ऐप श्रेणियाँ खोजें

GitHub रिपॉज़िटरीgochain/flutter_web3_provider

flutter_web3_provider

एक आसान उपयोग करने वाला वैलेट, जिसका उपयोग फ्लटर वेब एप्लिकेशन में मेटामास्क और अन्य डैप वॉलेट के साथ किया जा सकता है।

flutter_web3_provider प्रोजेक्ट कवर
स्टार
78
फ़ोर्क
24
अंतिम पुश (UTC)
23 अक्टू॰ 2024
प्रोजेक्ट स्थिति
सक्रिय

मूल README

यह अंग्रेज़ी मूल स्नैपशॉट है। नवीनतम सामग्री GitHub पर देखें।

flutter_web3_provider

Flutter wrapper for using web3 providers, ie: accessing window.ethereum.

NOTE: This is for web only!

Getting Started

For full example, see: https://github.com/gochain/flutter_web3_provider/blob/main/example/lib/main.dart

Add import import 'package:flutter_web3_provider/ethereum.dart';

Then you can access it just be using the ethereum variable.

if(ethereum != null){
    // then an ethereum provider was injected
    print(ethereum.selectedAddress);
}

Ask user to connect their wallet:

RaisedButton(
    child: Text("Connect Wallet"),
    onPressed: () async {
        var accounts = await promiseToFuture(
            ethereum.request(RequestParams(method: 'eth_requestAccounts')));
        print(accounts);
        String se = ethereum.selectedAddress;
        print("selectedAddress: $se");
        setState(() {
            selectedAddress = se;
        });
    },
)
Using ethers.js

Add ethers.js to web/index.html.

  <script type="module">
    import { ethers } from "https://cdnjs.cloudflare.com/ajax/libs/ethers/6.7.0/ethers.min.js";
    window.ethers = ethers
    // Your code here...
  </script>

Import package:

import 'package:flutter_web3_provider/ethers.dart';

Then create an ethers provider:

// For a read-only provider:
var provider = JsonRpcProvider("https://rpc.gochain.io");
// For a read-write provider (ie: metamask, trust wallet, etc)
var web3 = BrowserProvider(ethereum);

Then you can do things like check balance and submit transactions, etc:

var abalanceF = promiseToFuture(web3.getBalance(ethereum.selectedAddress));

Future tx = promiseToFuture(web3.Signer().sendTransaction(TxParams(
      to: to,
      value: "0x" +
          BigInt.parse(toBase(amount, 18).toString()).toRadixString(16))));

Or use a contract:

const erc20Abi = [
    // Some details about the token
    "function name() view returns (string)",
    "function symbol() view returns (string)",

    // Get the account balance
    "function balanceOf(address) view returns (uint)",

    // Send some of your tokens to someone else
    "function transfer(address to, uint amount)",

    // An event triggered whenever anyone transfers to someone else
    "event Transfer(address indexed from, address indexed to, uint amount)"
];
var contract = Contract(contractAddress, erc20Abi, web3);
// call balanceOf function
var usdcBalanceF = promiseToFuture(
          callMethod(contract, "balanceOf", [ethereum.selectedAddress]));
          
// to make a write transaction, first get the signer (this will use metamask/wallet)
contract = contract.connect(await promiseToFuture(web3.getSigner())); // uses the connected wallet as signer
// then call the function:
var res =
    await promiseToFuture(callMethod(contract, "transfer", [
    '0x39C5190c09ec04cF09C782bA4311C469473Ffe83',
    "0x" + amount.toString()).toRadixString(16)
    ]));

If you need to additional overrides like set gas price or passing the value param, you can add one extra param in the array with those fields, eg:

var res = await promiseToFuture(callMethod(
    contract, "transfer", ['0x39C5190c09ec04cF09C782bA4311C469473Ffe83', "0x" + amount.toString()).toRadixString(16), 
    TxParams(value: "1000000000000000000")]));

NOTES:

  • If you're using the human readable ABI's (ethers.js feature) like above, use uint, not uint256 even if the real abi is a uint256.
  • There are some common functions on the Contract, but you can also call any method using callMethod like above.

Developers

To publish:

make publish
GoChain GitHub avatar
GitHub लेखक

GoChain ↗

The web3 blockchain for enterprise.

भाषाएँDartHTMLNixSwiftMakefileKotlinObjective-C

इस रिपॉज़िटरी के पैकेज

उपयोग की गई निर्भरताएँ

निर्भरता सूची 3 आइटम

  • flutter{"sdk":"flutter"}
  • js^0.7.1
  • flutter_testडेवलपमेंट{"sdk":"flutter"}

अपने प्रोजेक्ट के लिए रिपॉज़िटरी कैसे चुनें?

उपयोग के अनुसार छाँटें, गतिविधि की तुलना करें और अपनाने से पहले मूल प्रोजेक्ट की आवश्यकताएँ जाँचें।

  1. नाम, लेखक या विवरण से खोजें और तकनीकी विषय से परिणाम सीमित करें।
  2. स्टार, फ़ोर्क और हाल के पुश की तुलना करें। स्टार रुचि दर्शाते हैं, गुणवत्ता की गारंटी नहीं।
  3. उपयोग से पहले GitHub पर README, लाइसेंस और Issues जाँचें।

स्रोत और रखरखाव

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗