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

पैकेज विवरणv2.0.2

flutter_web3_provider

Flutter web web3 provider

30-दिन डाउनलोड
80
लाइक
20
Pub अंक
25

पैकेज इंस्टॉल करें

flutter pub add flutter_web3_provider

पैकेज अवलोकन

सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।

एक फ्लटर पैकेज जो वेब एप्लिकेशन के लिए वेब3 तकनीकों के साथ एकीकरण की अनुमति देता है, जिससे उपयोगकर्ता अपने फ्लटर वेब एप्लिकेशन से सीधे इथेरियम-आधारित ब्लॉकचेन के साथ बातचीत कर सकते हैं। यह ब्लॉकचेन कनेक्शन, खाता राज्य और लेनदेन प्रबंधन के लिए प्रदाता पैटर्न के लागू करता है। वेब प्लेटफॉर्म के लिए विशेष रूप से डिज़ाइन किया गया है, यह मेटामास्क जैसे वॉलेट के लिए एक्सेस को सरल बनाता है और सामान्य वेब3 विधियों का समर्थन करता है, जैसे लेनदेन के हस्ताक्षर करना और स्मार्ट कॉन्ट्रैक्ट डेटा पढ़ना। यह पैकेज हल्का है और फ्लटर के राज्य प्रबंधन प्रणाली के साथ बिना किसी दिक्कत के काम करने के लिए बनाया गया है।

उपयोग

  • वेब ऐप्स में ईथेरियम वॉलेट से कनेक्ट करना
  • स्मार्ट कॉन्ट्रैक्ट्स से डेटा पढ़ना
  • ऑन-चेन लेनदेन पर हस्ताक्षर करना
  • उपयोगकर्ता वॉलेट खातों का प्रबंधन
  • डिसेंट्रलाइज्ड ऐप (dApp) कार्यक्षमता सक्षम करना

मुख्य विशेषताएँ

  • वेब के लिए केवल वेब3 एकीकरण
  • प्रोवाइडर-आधारित अवस्था प्रबंधन
  • MetaMask और समान वॉलेट के लिए समर्थन
  • सामान्य web3 संचालन के लिए सरल API
  • निर्मित कनेक्शन और डिस्कनेक्शन हैंडलिंग

इनके लिए उपयुक्त

  • Flutter विकासकर्मी dApps बना रहे हैं
  • वेब-आधारित ब्लॉकचेन एप्लिकेशन
  • वॉलेट कनेक्टिविटी की आवश्यकता वाले प्रोजेक्ट
  • ईथेरियम-संगत चेन का लक्ष्य बनाए वाले उपयोगकर्ता
  • Flutter के प्रतिक्रियाशील UI फ्रेमवर्क का उपयोग करने वाले विकासकर्मी

विचार योग्य बातें

  • केवल वेब प्लेटफॉर्म तक सीमित
  • ब्राउज़र-आधारित वॉलेट समर्थन की आवश्यकता है
  • बाहरी वॉलेट एक्सटेंशन पर निर्भर करता है
  • मोबाइल या डेस्कटॉप ऐप्स के लिए उपयुक्त नहीं
  • नेटवर्क समस्याओं के लिए अतिरिक्त त्रुटि संभाल की आवश्यकता हो सकती है

मूल README

संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।

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

श्रेणियाँ

निर्भरताएँ

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

  • js^0.7.1

सोर्स रिपॉज़िटरी

इस पैकेज का उपयोग करने वाले प्रोजेक्ट

अभी कोई डेटा उपलब्ध नहीं है।