Can't get returnValue from contract method call with nodejs

Hi,

I’m calling contract and I’m getting the tx hash and everything but I can’t find a way to get the response that I should get from the contract.
If I run dryRun… methods I get the response that I need but I can’t with normal methods.

The method checks if the data exists in the state based on the given parameter and should return object (with empty values or the data itself) at the end.

const signer = concordium.buildAccountSigner(secretKey);

const transaction = await RecheckContract[contractMethod](
  contractClient,
  {
    senderAddress: accountAddress,
    energy: concordium.Energy.create(10000),
    amount: concordium.CcdAmount.zero(),
  },
  contractArgs,
  signer
);

const tx = await client.waitForTransactionFinalization(transaction)
const transactionStatus = await client.getBlockItemStatus(transaction);

This is what I’m getting from the calls

TransactionHash {
  buffer: Uint8Array(32) [
    .....................
  ],
  __type: 'ccd_transaction_hash'
}
{
  blockHash: BlockHash {
    buffer: Uint8Array(32) [
       76, 143, 198, 178,  83, 187, 105, 190,
       38,  31,  55,  79, 161,  62, 104,  90,
        8, 150,  31,   9, 162, 121, 120, 191,
      177,  69, 106, 141,  46, 140, 102,   3
    ],
    typedJsonType: 'ccd_block_hash',
    __type: 'ccd_block_hash'
  },
  summary: {
    index: 0n,
    energyCost: Energy { value: 1847n, __type: 'ccd_energy' },
    hash: TransactionHash {
      buffer: Uint8Array(32) [
       .....................
      ],
      __type: 'ccd_transaction_hash'
    },
    type: 'accountTransaction',
    cost: 147165n,
    sender: AccountAddress {
      address: '.................',
      decodedAddress: Uint8Array(32) [
        ......................
      ],
      __type: 'ccd_account_address'
    },
    transactionType: 'update',
    events: [
      {
        tag: 'Updated',
        contractVersion: 1,
        address: ContractAddress {
          index: 10097n,
          subindex: 0n,
          __type: 'ccd_contract_address'
        },
        instigator: {
          type: 'AddressAccount',
          address: AccountAddress {
            address: '.................',
            decodedAddress: Uint8Array(32) [
              ................
            ],
            __type: 'ccd_account_address'
          }
        },
        amount: CcdAmount { microCcdAmount: 0n, __type: 'ccd_ccd_amount' },
        message: Parameter {
          buffer: Uint8Array(68) [
             64,   0,  0,  0, 100,  98, 97,  97,  97,  53,  98, 49,
             97,  49, 54, 97,  55,  99, 57,  55,  48,  51,  57, 52,
             48,  57, 53, 57,  51,  98, 51,  56,  98, 102,  54, 97,
             48,  55, 49, 98,  48,  53, 99,  50, 100,  53,  52, 53,
             98, 101, 99, 48,  48,  56, 53, 101,  50, 101, 101, 53,
            100,  55, 52, 97,  55, 101, 51,  54
          ],
          __type: 'ccd_parameter'
        },
        receiveName: ReceiveName {
          value: 'recheck.records',
          __type: 'ccd_receive_name'
        },
        events: []
      }
    ]
  }
}
{
  status: 'finalized',
  outcome: {
    blockHash: BlockHash {
      buffer: Uint8Array(32) [
         ..............
      ],
      typedJsonType: 'ccd_block_hash',
      __type: 'ccd_block_hash'
    },
    summary: {
      index: 0n,
      energyCost: Energy { value: 1847n, __type: 'ccd_energy' },
      hash: TransactionHash {
        buffer: Uint8Array(32) [
          ...........
        ],
        __type: 'ccd_transaction_hash'
      },
      type: 'accountTransaction',
      cost: 147165n,
      sender: AccountAddress {
        address: '.................',
        decodedAddress: Uint8Array(32) [
          ................
        ],
        __type: 'ccd_account_address'
      },
      transactionType: 'update',
      events: [
        {
          tag: 'Updated',
          contractVersion: 1,
          address: ContractAddress {
            index: 10097n,
            subindex: 0n,
            __type: 'ccd_contract_address'
          },
          instigator: {
            type: 'AddressAccount',
            address: AccountAddress {
              address: '.................',
              decodedAddress: Uint8Array(32) [
                ..............
              ],
              __type: 'ccd_account_address'
            }
          },
          amount: CcdAmount { microCcdAmount: 0n, __type: 'ccd_ccd_amount' },
          message: Parameter {
            buffer: Uint8Array(68) [
               64,   0,  0,  0, 100,  98, 97,  97,  97,  53,  98, 49,
               97,  49, 54, 97,  55,  99, 57,  55,  48,  51,  57, 52,
               48,  57, 53, 57,  51,  98, 51,  56,  98, 102,  54, 97,
               48,  55, 49, 98,  48,  53, 99,  50, 100,  53,  52, 53,
               98, 101, 99, 48,  48,  56, 53, 101,  50, 101, 101, 53,
              100,  55, 52, 97,  55, 101, 51,  54
            ],
            __type: 'ccd_parameter'
          },
          receiveName: ReceiveName {
            value: 'recheck.records',
            __type: 'ccd_receive_name'
          },
          events: []
        }
      ]
    }
  }
}

Hi byurhannurula,
when interacting with smart contracts on-chain, there are two main options available:

  • Reading from the smart contract state
  • Writing to the smart contract state

Reading can be done with the dryRun... function (generated by ccd-js-gen tool) which interacts with just one blockchain node to read some values from the smart contract state of that node. This interaction should be used if you call a function in the smart contract that has a returnValue. Think about the interaction as a 'simulation/dryRun`, the node will not persist any changes done in the interaction. No transaction is generated (hence no transaction hash) and the blockchain (the other nodes) are not aware of your interactions at all.

Writing to the smart contract so that your changes persist has to be done by sending a transaction on-chain. This transaction (while sent to one node in the blockchain) is then distributed to every other node in the blockchain and every node is aware and persists your changes permanently. You have to pay transaction fees for this action. Write functions in the smart contract usually don’t have a returnValue since they are not meant for reading.

1 Like

Doris thank you this helped me so much! :slight_smile: