simolus3 / web3dart

Ethereum library, written in Dart.
MIT License
442 stars 273 forks source link

Functions (in dart) which can read & submit transactions from smart contract #121

Open mato080 opened 3 years ago

mato080 commented 3 years ago

Hi everyone,

A one year ago I created following smart contract which interact with MetaMask through Web3 Injected provider on Remix. The purpose was to get, set and share access to personal information like name, age and so on... located in blockchain adresses. It works perfectly.

Now I'm trying to extend the functionality of the project and create Android application which can scan QR codes and grant access to information from blockchain address by clicking on a button. I tried used Java at first, then Kotlin but unfortunately without success. I was not able successfully interact with my Android program and blockchain (there was a lot of problems). Then I tried to use Flutter - dart. Now I'm able to interact with Ethereum smart contract MetaCoins which is primitive and something like "Hello World". I would like to use my own smart contract DecentralizedID, but unfortunately I'm new in web3dart as well as dart language and I've lack of knowledges how to write a code in dart which can interact with my smart contract. I can share my main.dart but it is dedicated for MetaCoin smart contract. Is anybody who could help me, or just write a functions which can read & submit transactions from my smart contract (smart_contract_DID.sol), please ? For example I would like to get data from the function showPerson which just should return msg.sender address. How can I get the data from this function ?

smart_contract_DID.sol

pragma solidity ^0.4.18;

contract Owned {
    address owner;

    function Owned() public {
        owner = msg.sender;
    }

    modifier onlyOwner {
        require(msg.sender == owner);
        _;
    }
}

contract DecentralizedID is Owned {

    struct Person {
        uint age;
        string first_name;
        string last_name;
        uint sharing_time;
        address shared_address;
    }

    mapping (address => Person) persons;
    address[] public personAccts;

    event personInfo(
        string first_name,
        string last_name,
        uint age
    );

    function sharing(address _address, uint time) public { 
        persons[_address].sharing_time = now + (time * 1 minutes);
        persons[msg.sender].shared_address = _address;
    }

    function views(address _address) view public returns (uint,string,string,uint){
        require(now < persons[msg.sender].sharing_time);
        require(persons[_address].shared_address == msg.sender);
        return (persons[_address].age, persons[_address].first_name, persons[_address].last_name, persons[msg.sender].sharing_time);
    }

    function setPerson(address _address, uint _age, string _first_name, string _last_name) public {     
        uint duplicates_count = 0;    
        var person = persons[_address];

        person.age = _age;
        person.first_name = _first_name;
        person.last_name = _last_name ;

        for(uint i=0; i < personAccts.length; i++){
            if (personAccts[i] == _address) {
                duplicates_count++;
                break;
            }
        }

        if (duplicates_count == 0) {
           personAccts.push(_address) -1;
        }

        personInfo(_first_name, _last_name, _age);
    }

    function getPersons() view onlyOwner public returns(address[]) {
        return personAccts;
    }

    function getPerson(address _address) view onlyOwner public returns (uint, string, string) {
        return (persons[_address].age, persons[_address].first_name, persons[_address].last_name);
    }

    function getPersonFree(address _address) view public returns (uint, string, string) {
        return (persons[_address].age, persons[_address].first_name, persons[_address].last_name);
    }

    function countPersons() view public returns (uint) {
        return personAccts.length;
    }

    function showPerson() view public returns (address) {
        return msg.sender;   
    }
}

main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:http/http.dart';
import 'package:web3dart/web3dart.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Client httpClient;
  Web3Client ethClient;

  String lastTransactionHash;
  String _balance;
  String _address;
  @override
  void initState() {
    super.initState();
    httpClient = new Client();
    ethClient = new Web3Client("https://ropsten.infura.io/v3/<id redacted>", httpClient);
  }

  Future<DeployedContract> loadContract() async {
    String abiCode = await rootBundle.loadString("assets/abi.json");
    String contractAddress = "0x9dA0144fcd933df0c0A5646568Cb90dd4620F545";

    final contract = DeployedContract(ContractAbi.fromJson(abiCode, "MetaCoin"),
        EthereumAddress.fromHex(contractAddress));
    return contract;
  }

  Future<String> submit(String functionName, List<dynamic> args) async {
    EthPrivateKey credentials = EthPrivateKey.fromHex(
        "<MY_PRIVATE_KEY>");

    DeployedContract contract = await loadContract();

    final ethFunction = contract.function(functionName);

    final address = EthereumAddress.fromHex('0x9fe1C8b05528c9a21ac905438c721B9e69F44336');
    final ethAmount = await ethClient.getBalance(address);

    setState(() {
      _balance = '${ethAmount.getValueInUnit(EtherUnit.ether)}';
      _address = '${address}';
    });

    var result = await ethClient.sendTransaction(
        credentials,
        Transaction.callContract(
          contract: contract,
          function: ethFunction,
          parameters: args,
        ),
        chainId: 3
    );
    return result;
  }

  Future<List<dynamic>> query(String functionName, List<dynamic> args) async {
    final contract = await loadContract();
    final ethFunction = contract.function(functionName);
    final data = await ethClient.call(
        contract: contract, function: ethFunction, params: args);
    return data;
  }

  Future<String> sendCoin(String targetAddressHex, int amount) async {
    EthereumAddress address = EthereumAddress.fromHex(targetAddressHex);
    var bigAmount = BigInt.from(amount);
    var response = await submit("sendCoin", [address, bigAmount]);
    return response;
  }

  Future<List<dynamic>> getBalance(String targetAddressHex) async {
    EthereumAddress address = EthereumAddress.fromHex(targetAddressHex);
    List<dynamic> result = await query("getBalance", [address]);
    return result;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[

            FutureBuilder(
              future: getBalance("0x9fe1C8b05528c9a21ac905438c721B9e69F44336"),
              builder: (context, snapshot) {
                if (snapshot.hasData) {
                  return Text(
                      'My balance is $_balance Eth, \n My address $_address, \n I have this many MetaCoin ${snapshot.data[0]}');

                } else
                  return Text('Loading...');
              },
            ),
            RaisedButton(
              child: Text("Send some MetaCoins"),
              onPressed: () async {
                var result = await sendCoin(
                    "0x35BC1c67e672F01b9977399599AB49cb8042761A", 2);
                setState(() {
                  lastTransactionHash = result;
                });
              },
            ),
            Text("Last transaction hash: $lastTransactionHash")
          ],
        ),
      ),
    );
  }
}

Thank you for each help, I appreciate it !

simolus3 commented 3 years ago

First, you'll need to extract the abi with solc smart_contract_DID.sol --abi, which should give you a JSON output. You can use that with ContractAbi.fromJson(yourAbi, 'DecentralizedID') to make calls in Dart. The example contains more code to set this up, but your code looks alright to me.

For example I would like to get data from the function showPerson which just should return msg.sender address. How can I get the data from this function ?

Future<EthereumAddress> showPerson() async {
  final result = await client.call(
    sender: await credentials.extractAddress(),
    contract: contract,
    function: contract.function('showPerson'),
    params: const [],
  );
  return result.single as EthereumAddress;
}
mato080 commented 3 years ago

Thank you Simon, I will test this soon and I will provide some feedback after that. Thank you very much for your time and help.

Happy New Year 2021 !

mato080 commented 3 years ago

Hello,

@simolus3 I tried to use following code (but little bit modified your suggested code, because there I had an error) :

  Future<EthereumAddress> showPerson() async {
    EthPrivateKey credentials = EthPrivateKey.fromHex(
        "cf2e2741019e04b[MY_PRIVATE_KEY]528ba4fdd1c2925fd");
    final contract = await loadContract();
    final result = await ethClient.call(
      sender: await credentials.extractAddress(),
      contract: contract,
      function: contract.function('showPerson'),
      params: const [],
    );
    return result.single as EthereumAddress;
  }

Now, I'm not able to display results :

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[

            FutureBuilder(
              future: showPerson(),
              builder: (context, snapshot) {
                if (snapshot.hasData) {
                  return Text(
                      'This is result #1 : ${snapshot.data[0]}');
                } else
                  return Text('This is result #2 : $showPerson() or ${showPerson()} ');
              },
            ),
          ],
        ),
      ),
    );
  }

What is wrong ?

simolus3 commented 3 years ago

It's hard to say what's going wrong here without seeing a stacktrace or the details of the exception. You can print snapshot.error to see the error if something went wrong.

mato080 commented 3 years ago

I printed snapshot.error : Bad state: No element

Just please tell me how to display the results from function showPerson(). I think that I did a mistake in this....

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[

            FutureBuilder(
              future: showPerson(),
              builder: (context, snapshot) {
                if (snapshot.hasData) {
                  return Text(
                      'This is result #1 : ${snapshot.data[0]}');
                } else
                  return Text('This is result #2 : $showPerson() or ${showPerson()} ');
              },
            ),
          ],
        ),
      ),
    );
  }

I tried this :

return Text('This is result #2 : $showPerson() or ${showPerson()} ');

but maybe it is wrong.

mato080 commented 3 years ago

Here is my logcat :

    --------- beginning of main
2021-01-09 16:44:22.122 4617-4617/? W/adbd: timeout expired while flushing socket, closing
2021-01-09 16:44:22.177 0-0/? D/logd: logdr: UID=2000 GID=2000 PID=16086 b tail=0 logMask=99 pid=0 start=0ns timeout=0ns
2021-01-09 16:44:25.531 0-0/? D/logd: logdr: UID=2000 GID=2000 PID=16091 n tail=1 logMask=99 pid=0 start=0ns timeout=0ns
2021-01-09 16:44:25.574 0-0/? D/logd: logdr: UID=2000 GID=2000 PID=16094 n tail=1 logMask=99 pid=0 start=0ns timeout=0ns
2021-01-09 16:44:25.647 0-0/? D/logd: logdr: UID=2000 GID=2000 PID=16099 b tail=0 logMask=99 pid=0 start=1610207065531000000ns timeout=0ns

    --------- beginning of system
2021-01-09 16:44:32.871 524-897/system_process I/ActivityManager: Force stopping de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample appid=10154 user=0: from pid 16103
2021-01-09 16:44:32.873 16103-16105/? I/cmd: oneway function results will be dropped but finished with status OK and parcel size 4
2021-01-09 16:44:32.879 905-905/com.android.phone D/CarrierSvcBindHelper: No carrier app for: 0
2021-01-09 16:44:32.923 16108-16110/? I/cmd: oneway function results will be dropped but finished with status OK and parcel size 4
2021-01-09 16:44:32.993 524-1533/system_process I/ActivityTaskManager: START u0 {act=android.intent.action.RUN flg=0x30000000 cmp=de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample/.MainActivity (has extras)} from uid 2000
2021-01-09 16:44:32.993 524-544/system_process D/EventSequenceValidator: Transition from REPORT_FULLY_DRAWN to INTENT_STARTED
2021-01-09 16:44:32.997 393-393/? I/perfetto: ing_service_impl.cc:758 Configured tracing session 32, #sources:1, duration:5000 ms, #buffers:1, total buffer size:4096 KB, total sessions:1, uid:1071 session name: ""
2021-01-09 16:44:32.998 388-388/? I/perfetto: probes_producer.cc:230  Ftrace setup (target_buf=32)
2021-01-09 16:44:33.000 16115-16117/? I/cmd: oneway function results will be dropped but finished with status OK and parcel size 4
2021-01-09 16:44:33.005 524-544/system_process D/CompatibilityChangeReporter: Compat change id reported: 135634846; UID 10154; state: DISABLED
2021-01-09 16:44:33.005 524-551/system_process D/CompatibilityChangeReporter: Compat change id reported: 143937733; UID 10154; state: DISABLED
2021-01-09 16:44:33.006 524-544/system_process D/EventSequenceValidator: Transition from INTENT_STARTED to ACTIVITY_LAUNCHED
2021-01-09 16:44:33.032 287-287/? D/Zygote: Forked child process 16124
2021-01-09 16:44:33.035 388-388/? I/perfetto: ftrace_procfs.cc:176    enabled ftrace
2021-01-09 16:44:33.009 0-0/? W/perfetto: enabled ftrace
2021-01-09 16:44:33.042 16124-16124/? I/ethereum_sampl: Not late-enabling -Xcheck:jni (already on)
2021-01-09 16:44:33.045 524-551/system_process I/ActivityManager: Start proc 16124:de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample/u0a154 for pre-top-activity {de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample.MainActivity}
2021-01-09 16:44:33.045 305-343/? D/goldfish-address-space: allocate: Ask for block of size 0xe10000
2021-01-09 16:44:33.045 305-343/? D/goldfish-address-space: allocate: ioctl allocate returned offset 0x3fba84000 size 0xe11000
2021-01-09 16:44:33.069 16124-16124/? I/ethereum_sampl: Unquickening 12 vdex files!
2021-01-09 16:44:33.071 16124-16124/? W/ethereum_sampl: Unexpected CPU variant for X86 using defaults: x86
2021-01-09 16:44:33.081 4617-4632/? I/adbd: jdwp connection from 16124
2021-01-09 16:44:33.131 524-897/system_process W/InputReader: Device virtio_input_multi_touch_10 is associated with display ADISPLAY_ID_NONE.
2021-01-09 16:44:33.132 524-897/system_process W/InputReader: Device virtio_input_multi_touch_4 is associated with display ADISPLAY_ID_NONE.
2021-01-09 16:44:33.132 524-897/system_process W/InputReader: Device virtio_input_multi_touch_9 is associated with display ADISPLAY_ID_NONE.
2021-01-09 16:44:33.132 524-897/system_process W/InputReader: Device virtio_input_multi_touch_11 is associated with display ADISPLAY_ID_NONE.
2021-01-09 16:44:33.132 524-897/system_process W/InputReader: Device virtio_input_multi_touch_5 is associated with display ADISPLAY_ID_NONE.
2021-01-09 16:44:33.132 524-897/system_process W/InputReader: Device virtio_input_multi_touch_2 is associated with display ADISPLAY_ID_NONE.
2021-01-09 16:44:33.132 524-897/system_process W/InputReader: Device virtio_input_multi_touch_7 is associated with display ADISPLAY_ID_NONE.
2021-01-09 16:44:33.132 524-897/system_process W/InputReader: Device virtio_input_multi_touch_6 is associated with display ADISPLAY_ID_NONE.
2021-01-09 16:44:33.132 524-897/system_process W/InputReader: Device virtio_input_multi_touch_3 is associated with display ADISPLAY_ID_NONE.
2021-01-09 16:44:33.132 524-897/system_process W/InputReader: Device virtio_input_multi_touch_8 is associated with display ADISPLAY_ID_NONE.
2021-01-09 16:44:33.136 524-897/system_process W/InputReader: Device virtio_input_multi_touch_10 is associated with display ADISPLAY_ID_NONE.
2021-01-09 16:44:33.136 524-897/system_process W/InputReader: Device virtio_input_multi_touch_4 is associated with display ADISPLAY_ID_NONE.
2021-01-09 16:44:33.136 524-897/system_process W/InputReader: Device virtio_input_multi_touch_9 is associated with display ADISPLAY_ID_NONE.
2021-01-09 16:44:33.136 524-897/system_process W/InputReader: Device virtio_input_multi_touch_11 is associated with display ADISPLAY_ID_NONE.
2021-01-09 16:44:33.137 524-897/system_process W/InputReader: Device virtio_input_multi_touch_5 is associated with display ADISPLAY_ID_NONE.
2021-01-09 16:44:33.137 524-897/system_process W/InputReader: Device virtio_input_multi_touch_2 is associated with display ADISPLAY_ID_NONE.
2021-01-09 16:44:33.137 524-897/system_process W/InputReader: Device virtio_input_multi_touch_7 is associated with display ADISPLAY_ID_NONE.
2021-01-09 16:44:33.137 524-897/system_process W/InputReader: Device virtio_input_multi_touch_6 is associated with display ADISPLAY_ID_NONE.
2021-01-09 16:44:33.137 524-897/system_process W/InputReader: Device virtio_input_multi_touch_3 is associated with display ADISPLAY_ID_NONE.
2021-01-09 16:44:33.137 524-897/system_process W/InputReader: Device virtio_input_multi_touch_8 is associated with display ADISPLAY_ID_NONE.
2021-01-09 16:44:33.176 16124-16124/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample D/ApplicationLoaders: Returning zygote-cached class loader: /system/framework/android.test.base.jar
2021-01-09 16:44:33.180 1168-8064/com.google.android.gms E/SQLiteDatabase: Error inserting flex_time=2626000 job_id=-1 period=5254000 source=16 requires_charging=0 preferred_network_type=1 target_class=com.google.android.gms.measurement.PackageMeasurementTaskService user_id=0 target_package=com.google.android.gms tag=Measurement.PackageMeasurementTaskService.UPLOAD_TASK_TAG task_type=0 required_idleness_state=0 service_kind=0 source_version=201817000 preferred_charging_state=1 required_network_type=0 runtime=1610207073170 retry_strategy={"maximum_backoff_seconds":{"3600":0},"initial_backoff_seconds":{"30":0},"retry_policy":{"0":0}} last_runtime=0
    android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: pending_ops.tag, pending_ops.target_class, pending_ops.target_package, pending_ops.user_id (code 2067 SQLITE_CONSTRAINT_UNIQUE)
        at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
        at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:938)
        at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:790)
        at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:88)
        at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1701)
        at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1570)
        at apla.a(:com.google.android.gms@201817022@20.18.17 (040700-311416286):78)
        at apkp.a(:com.google.android.gms@201817022@20.18.17 (040700-311416286):196)
        at apkp.a(:com.google.android.gms@201817022@20.18.17 (040700-311416286):20)
        at apkp.a(:com.google.android.gms@201817022@20.18.17 (040700-311416286):190)
        at apgy.run(:com.google.android.gms@201817022@20.18.17 (040700-311416286):8)
        at sji.b(:com.google.android.gms@201817022@20.18.17 (040700-311416286):12)
        at sji.run(:com.google.android.gms@201817022@20.18.17 (040700-311416286):7)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at spj.run(:com.google.android.gms@201817022@20.18.17 (040700-311416286):0)
        at java.lang.Thread.run(Thread.java:923)
2021-01-09 16:44:33.219 305-343/? D/goldfish-address-space: allocate: Ask for block of size 0x900000
2021-01-09 16:44:33.219 305-343/? D/goldfish-address-space: allocate: ioctl allocate returned offset 0x3fb183000 size 0x901000
2021-01-09 16:44:33.230 16124-16124/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample D/NetworkSecurityConfig: Using Network Security Config from resource network_security_config debugBuild: true
2021-01-09 16:44:33.233 16124-16124/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample D/NetworkSecurityConfig: Using Network Security Config from resource network_security_config debugBuild: true
2021-01-09 16:44:33.235 16124-16124/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample I/System.out: should load native is true
2021-01-09 16:44:33.259 16124-16150/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample I/ResourceExtractor: Found extracted resources res_timestamp-1-1610206084320
2021-01-09 16:44:33.265 16124-16152/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
2021-01-09 16:44:33.269 16124-16152/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
2021-01-09 16:44:33.274 16124-16152/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
2021-01-09 16:44:33.362 16124-16124/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample D/HostConnection: HostConnection::get() New Host Connection established 0xd0ac72b0, tid 16124
2021-01-09 16:44:33.366 16124-16124/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2 
2021-01-09 16:44:33.369 173-173/? I/hwservicemanager: getTransport: Cannot find entry android.hardware.configstore@1.0::ISurfaceFlingerConfigs/default in either framework or device manifest.
2021-01-09 16:44:33.398 16124-16124/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample D/EGL_emulation: eglCreateContext: 0xd0ac6210: maj 2 min 0 rcv 2
2021-01-09 16:44:33.467 16124-16124/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample D/EGL_emulation: eglCreateContext: 0xd0ac67c0: maj 2 min 0 rcv 2
2021-01-09 16:44:33.508 16124-16156/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample D/HostConnection: HostConnection::get() New Host Connection established 0xd0ac77f0, tid 16156
2021-01-09 16:44:33.513 16124-16156/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2 
2021-01-09 16:44:33.672 16124-16156/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample D/EGL_emulation: eglMakeCurrent: 0xd0ac67c0: ver 2 0 (tinfo 0xbac03d50) (first time)
2021-01-09 16:44:33.747 16124-16163/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample I/flutter: Observatory listening on http://127.0.0.1:33411/iUjVXhQKE_M=/
2021-01-09 16:44:33.871 524-7146/system_process D/HostConnection: HostConnection::get() New Host Connection established 0xe97ad8f0, tid 7146
2021-01-09 16:44:33.896 524-7146/system_process D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2 
2021-01-09 16:44:33.899 524-7146/system_process W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2021-01-09 16:44:33.924 524-7146/system_process D/EGL_emulation: eglCreateContext: 0xae4c1350: maj 2 min 0 rcv 2
2021-01-09 16:44:33.954 16124-16124/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample W/ethereum_sampl: Accessing hidden method Landroid/view/accessibility/AccessibilityNodeInfo;->getSourceNodeId()J (greylist,test-api, reflection, allowed)
2021-01-09 16:44:33.955 16124-16124/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample W/ethereum_sampl: Accessing hidden method Landroid/view/accessibility/AccessibilityRecord;->getSourceNodeId()J (greylist, reflection, allowed)
2021-01-09 16:44:33.955 16124-16124/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample W/ethereum_sampl: Accessing hidden field Landroid/view/accessibility/AccessibilityNodeInfo;->mChildNodeIds:Landroid/util/LongArray; (greylist, reflection, allowed)
2021-01-09 16:44:33.955 16124-16124/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample W/ethereum_sampl: Accessing hidden method Landroid/util/LongArray;->get(I)J (greylist, reflection, allowed)
2021-01-09 16:44:33.975 524-7146/system_process D/EGL_emulation: eglMakeCurrent: 0xae4c1350: ver 2 0 (tinfo 0xb43dcc10) (first time)
2021-01-09 16:44:34.055 16124-16149/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample D/HostConnection: HostConnection::get() New Host Connection established 0xd0ac5250, tid 16149
2021-01-09 16:44:34.072 16124-16149/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2 
2021-01-09 16:44:34.072 16124-16149/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2021-01-09 16:44:34.090 305-343/? D/goldfish-address-space: allocate: Ask for block of size 0xd23c00
2021-01-09 16:44:34.091 305-343/? D/goldfish-address-space: allocate: ioctl allocate returned offset 0x3f5afe000 size 0xd25000
2021-01-09 16:44:34.094 16124-16149/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample D/EGL_emulation: eglCreateContext: 0xe97b5ca0: maj 2 min 0 rcv 2
2021-01-09 16:44:34.116 173-173/? I/hwservicemanager: getTransport: Cannot find entry android.hardware.graphics.mapper@4.0::IMapper/default in either framework or device manifest.
2021-01-09 16:44:34.116 16124-16155/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample I/Gralloc4: mapper 4.x is not supported
2021-01-09 16:44:34.119 16124-16155/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample D/HostConnection: createUnique: call
2021-01-09 16:44:34.119 16124-16155/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample D/HostConnection: HostConnection::get() New Host Connection established 0xd0ac6750, tid 16155
2021-01-09 16:44:34.120 16124-16155/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample D/goldfish-address-space: allocate: Ask for block of size 0x100
2021-01-09 16:44:34.122 16124-16155/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample D/goldfish-address-space: allocate: ioctl allocate returned offset 0x3fcafd000 size 0x2000
2021-01-09 16:44:34.165 16124-16149/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample D/EGL_emulation: eglMakeCurrent: 0xe97b5ca0: ver 2 0 (tinfo 0xbac05370) (first time)
2021-01-09 16:44:34.168 16124-16155/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2 
2021-01-09 16:44:34.175 16124-16155/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample D/HostConnection: HostConnection::get() New Host Connection established 0xd0ac6b40, tid 16155
2021-01-09 16:44:34.183 305-343/? D/goldfish-address-space: allocate: Ask for block of size 0xe10000
2021-01-09 16:44:34.183 305-343/? D/goldfish-address-space: allocate: ioctl allocate returned offset 0x3f1fe8000 size 0xe11000
2021-01-09 16:44:34.208 16124-16155/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2 
2021-01-09 16:44:34.271 16124-16155/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample D/EGL_emulation: eglMakeCurrent: 0xd0ac6210: ver 2 0 (tinfo 0xbac03eb0) (first time)
2021-01-09 16:44:34.535 305-343/? D/goldfish-address-space: allocate: Ask for block of size 0xe10000
2021-01-09 16:44:34.535 305-343/? D/goldfish-address-space: allocate: ioctl allocate returned offset 0x3eee3e000 size 0xe11000
2021-01-09 16:44:34.596 16124-16124/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample I/Choreographer: Skipped 33 frames!  The application may be doing too much work on its main thread.
2021-01-09 16:44:34.604 524-549/system_process D/ArtManagerInternalImpl: /data/misc/iorapd/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample/1/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample.MainActivity/compiled_traces/compiled_trace.pb doesn't exist
2021-01-09 16:44:34.608 524-549/system_process I/ActivityTaskManager: Displayed de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample/.MainActivity: +1s608ms
2021-01-09 16:44:34.610 524-544/system_process D/EventSequenceValidator: Transition from ACTIVITY_LAUNCHED to ACTIVITY_FINISHED
2021-01-09 16:44:37.175 305-343/? D/goldfish-address-space: allocate: Ask for block of size 0xd23c00
2021-01-09 16:44:37.175 305-343/? D/goldfish-address-space: allocate: ioctl allocate returned offset 0x3fbb70000 size 0xd25000
2021-01-09 16:44:37.241 524-549/system_process I/ActivityTaskManager: Fully drawn de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample/.MainActivity: +4s248ms
2021-01-09 16:44:37.244 524-544/system_process D/EventSequenceValidator: Transition from ACTIVITY_FINISHED to REPORT_FULLY_DRAWN
2021-01-09 16:44:37.303 305-343/? D/goldfish-address-space: allocate: Ask for block of size 0xe10000
2021-01-09 16:44:37.304 305-343/? D/goldfish-address-space: allocate: ioctl allocate returned offset 0x3fd9ac000 size 0xe11000
2021-01-09 16:44:37.570 305-343/? D/goldfish-address-space: allocate: Ask for block of size 0xd23c00
2021-01-09 16:44:37.571 305-343/? D/goldfish-address-space: allocate: ioctl allocate returned offset 0x3ee119000 size 0xd25000
2021-01-09 16:44:38.006 388-388/? I/perfetto: probes_producer.cc:329  Producer stop (id=32)
2021-01-09 16:44:38.008 393-393/? I/perfetto: ng_service_impl.cc:1948 Tracing session 32 ended, total sessions:0
2021-01-09 16:44:38.008 388-388/? I/perfetto: ftrace_procfs.cc:183    disabled ftrace
2021-01-09 16:44:37.982 0-0/? W/perfetto: disabled ftrace
2021-01-09 16:44:38.010 402-16119/? I/iorapd: Perfetto TraceBuffer saved to file: /data/misc/iorapd/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample/1/de.christopher_marx.flutter_ethereum_sample.flutter_ethereum_sample.MainActivity/raw_traces/1610207078008753700.perfetto_trace.pb
2021-01-09 16:44:39.677 1270-1352/com.google.android.inputmethod.latin I/PeriodicStatsRunner: PeriodicStatsRunner.call():180 call()
2021-01-09 16:44:39.677 1270-1352/com.google.android.inputmethod.latin I/PeriodicStatsRunner: PeriodicStatsRunner.call():184 No submit PeriodicStats since input started.
2021-01-09 16:44:42.324 483-483/? E/netmgr: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:network' service: Invalid argument
2021-01-09 16:44:42.324 483-483/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2021-01-09 16:44:53.177 490-490/? E/wifi_forwarder: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:wififorward' service: Invalid argument
2021-01-09 16:44:53.177 490-490/? E/wifi_forwarder: RemoteConnection failed to initialize: RemoteConnection failed to open pipe
2021-01-09 16:45:42.372 483-483/? E/netmgr: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:network' service: Invalid argument
2021-01-09 16:45:42.372 483-483/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2021-01-09 16:45:53.222 490-490/? E/wifi_forwarder: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:wififorward' service: Invalid argument
2021-01-09 16:45:53.223 490-490/? E/wifi_forwarder: RemoteConnection failed to initialize: RemoteConnection failed to open pipe
2021-01-09 16:46:42.432 483-483/? E/netmgr: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:network' service: Invalid argument
2021-01-09 16:46:42.433 483-483/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2021-01-09 16:46:53.233 490-490/? E/wifi_forwarder: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:wififorward' service: Invalid argument
2021-01-09 16:46:53.233 490-490/? E/wifi_forwarder: RemoteConnection failed to initialize: RemoteConnection failed to open pipe
2021-01-09 16:47:13.816 524-657/system_process E/ClipboardService: Denying clipboard access to com.android.chrome, application is not in focus nor is it a system service for user 0

(unfortunately don't know language of logcat to make it colorful)

The issue starts here : 2021-01-09 16:47:42.445 483-483/? E/netmgr: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:network' service: Invalid argument

Maybe I'm wrong and just don't know how to display the results from showPerson function.....

Any idea, please ?

mato080 commented 3 years ago

Hi,

I tried to run the previous program with MetaCoin.sol contract and it works fine. I checked logcat results and there I retrieved the same output as I have with my program.

2021-01-09 17:35:43.902 483-483/? E/netmgr: qemu_pipe_open_ns:62: Could not connect to the 'pipe:qemud:network' service: Invalid argument
2021-01-09 17:35:43.902 483-483/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument

So I think that program is launching without any important error message, but maybe I don't know how correctly display results of function showPerson, or maybe the problem is in declared function :

  Future<EthereumAddress> showPerson() async {
    EthPrivateKey credentials = EthPrivateKey.fromHex(
        "cf2e2741019e04b[MY_PRIVATE_KEY]528ba4fdd1c2925fd");
    final contract = await loadContract();
    final result = await ethClient.call(
      sender: await credentials.extractAddress(),
      contract: contract,
      function: contract.function('showPerson'),
      params: const [],
    );
    return result.single as EthereumAddress;
  }
mato080 commented 3 years ago

Hello everyone,

I've found the problem !

I did stupid mistake - after a lot of hours of investigation I've found that there is only one function that is working for me = getBalance as well when I used other smart contract (other functions has output null), which makes me think that there is something wrong with my ABI file. ....and yes - I was everytime saving my ABI to wrong ABI file which has been located with similar project name ! Arghh 🥇

Ok, move forward : Now I tried function showPerson where as result of the function from smart contract I receive 0x0000000000000000000000000000000000000000, instead of I should receive my actually connected blockchain address connected in MetaMask at the time.

    function showPerson() view public returns (address) {
        return msg.sender;   
    }

msg.sender = gives the direct sender of the message, so for example a contract that passed it along.

Any idea why I retrieve 0x0000000000000000000000000000000000000000 instead of my own blockchain address ?