web3_universal_contract 0.1.0+1 copy "web3_universal_contract: ^0.1.0+1" to clipboard
web3_universal_contract: ^0.1.0+1 copied to clipboard

Smart contract interaction layer for Web3 Universal SDK. simplifying ABI encoding, event decoding, and method calls.

example/main.dart

import 'dart:convert';

import 'package:web3_universal_chains/web3_universal_chains.dart';
import 'package:web3_universal_client/web3_universal_client.dart';
import 'package:web3_universal_contract/web3_universal_contract.dart';

void main() async {
  // ERC20 ABI snippet for balancing
  const abi = [
    {
      'constant': true,
      'inputs': [
        {'name': '_owner', 'type': 'address'}
      ],
      'name': 'balanceOf',
      'outputs': [
        {'name': 'balance', 'type': 'uint256'}
      ],
      'type': 'function',
    }
  ];

  final client = ClientFactory.createPublicClient(
    rpcUrl: 'https://eth-mainnet.g.alchemy.com/v2/your-api-key',
    chain: Chains.ethereum,
  );
  final contractAddress = '0xdAC17F958D2ee523a2206206994597C13D831ec7'; // USDT

  // Initialize the contract
  final contract = Contract(
    address: contractAddress,
    abi: jsonEncode(abi),
    publicClient: client,
  );

  // Prepare the call
  // For typed call we might need TypedContract or similar,
  // but Contract.read works with function name.
  final vitalik = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045';

  // Execute call
  final result = await contract.read('balanceOf', [vitalik]);

  print('USDT Balance: ${result.first}');

  client.dispose();
}
0
likes
160
points
2
downloads

Publisher

unverified uploader

Weekly Downloads

Smart contract interaction layer for Web3 Universal SDK. simplifying ABI encoding, event decoding, and method calls.

Homepage
Repository (GitHub)
View/report issues

Topics

#web3 #ethereum #smart-contracts

Documentation

API reference

License

MIT (license)

Dependencies

web3_universal_abi, web3_universal_client, web3_universal_core, web3_universal_crypto, web3_universal_provider, web3_universal_signer

More

Packages that depend on web3_universal_contract