Consider there are 3 contracts: BankA, customer, and BankB.BankA transfers some ethers to customer and after that some customer's state variables must be changed (in a better words be updated). It must also happen for BankB and customer. But the changes are not stable and their values return back to default.


pragma solidity^0.5.12;
contract customer{
  address payable[]  public onboarded;
  bytes public fullname;
  bytes public id;
  bool public KYC;
  uint256 public categor;
  function prime(bytes memory fname, bytes memory iden, bool KYCresult, uint256 level, address payable bank) public{
  function() external payable{}
function Array() public returns(uint256){
return onboarded.length;


pragma solidity ^0.5.12;

import "./customer.sol";
contract BankA{
  function creation() public returns(string memory){
    customer client=new customer();
    client.prime("Alireza Kiakojouri","5000077563", true, 2, here);
    return uint2str(uint(client.Array()));
  function uint2str(uint _i) internal pure returns (string memory ) {
    if (_i == 0) {
        return "0";
    uint j = _i;
    uint len;
    while (j != 0) {
        j /= 10;
    bytes memory bstr = new bytes(len);
    uint k = len - 1;
    while (_i != 0) {
        bstr[k--] = byte(uint8(48 + _i % 10));
        _i /= 10;
    return string(bstr);
  function() external payable{}

Whenever i call creation function of BankA in Truffle, it represents length of the onboarded array equal to "1" that is true:

enter image description here

But whenever i call creation function of BankB, it represents "1" again while it should be "2".

enter image description here

What is the problem and is there any solution? Thank you.

  • This question is not clear. Please post an example that compiles with indenting to be readable, clearly describe the steps to replicate the problem and the result you expected/want. – Rob Hitchens Feb 7 '20 at 16:58
  • In function creation, you do customer client=new customer(). So what exactly did you expect from a new customer, to somehow know about total customer count??? Also, as mentioned above - your question is chaotic, and as not mentioned above - there are missing definitions in your code, like - what exactly is Array??? – goodvibration Feb 7 '20 at 17:00
  • In customer's smart contract, prime function sets some KYC information that BankA supplies them and after that pushes address of BankA on onboarded array. Length of the array is zero in first and after client.prime(...) in creation it will be "1". Codes of BankA are qual to codes of BankB. But whenever BankB runs client.prime(...) length of that array doesn't be equal to "2" and be "1" again. – Alireza Feb 7 '20 at 17:12
  • I had forgotten adding Array() function in customer's smart contract because of copying Notepad. In the end of customer's code it added. – Alireza Feb 7 '20 at 17:25
  • This array is in the customer contract. Obviously, whenever you create a new customer instance, the initial length of this array is 0, and after you push an address to this array, its length becomes 1. Each customer instance holds an independent array. – goodvibration Feb 7 '20 at 17:27

So, don't use new in BankA. It doesn't give you what you want. To access to current state of a contract you need to use interface or you can interact with the smart contract immediately if you have the called contract's Solidity code and import it to the .sol file in that the caller contract is there. The link below describes how to use interface:


Immediately interaction is fully similar to interface but you need to import the called .sol file.


In general, using new keyword, gets a new instance with the default state. When you use new customer(); it gives you the customer contract by its initial state. To call a contract by its current state you should use


After that you can call its function by something like this:

customer(<address>).prime(Arg1, Arg2, ...)


Whenever we define customer contract with new customer(); in BankA and BankB, that means BankA and BankB access to default data of customer. Default data is that same data was embedded in smart contract before deployment process. To change the values should apply the below command in banks contracts:

customer(“address of customer contract”).prime("Alireza Kiakojouri","5000077563", true, 2, here);

After that, banks will access the changed or updated values.

Thus, just replace

 customer client=new customer();
 client.prime(Alireza Kiakojouri","5000077563", true, 2, here);


customer(“address of customer contract”).prime("Alireza Kiakojouri","5000077563", true, 2, here);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.