Autonomous Contract System - Need plausibility input

I need some more input as to an idea that I had and the viability of it. I’m still too new to smart contracts to know if this would be a possibility.

Is it possible to make a network of smart contracts that would essentially think for itself? What I mean by that is: If I had a central contract, contract A, could other wing contracts be made that would change their state based on certain conditions in Contract A ? For example, Contract B changes a boolean value in itself based on the balance of Contract A. Or another example, Contract C is triggered based on a value of Contract A which is just a counter based off how many times a certain function is called.

Would the wing contracts need to have gas in them to be able to change their state? Do the wing contracts need an outside trigger to call them before anything happened?

The end goal would be to have certain triggers in these wing contracts that could be read by an offchain entity, say IFTTT or an AWS lambda which would then perform an action such as sending a tweet or posting on a website. This would all be part of a game or product that users can interact with. Would want to simulate an autonomous being in a way and have it think for itself.

I know I’m not writing this exactly how I envision it in my brain but I’m hoping it makes enough sense where you can understand the basis.

1 Like

Hi @pantsme

A transaction needs to be initiated by an External Account and it is that account that pays the gas (unless using the Gas Station Network). Which means the contracts would need an external trigger to initiate a transaction executing a function on one of the contracts (which can then execute functions on the other contracts) to change state.

You could have external event listeners which listen for events to be emitted by one of your smart contract functions to then perform an external event e.g. send a tweet, or they could periodically call view functions in your contracts to read the current state and perform external actions.

I suggest that you try it out, perhaps start with a single simple contract e.g. a counter that emits an event when the value is incremented.

pragma solidity ^0.5.0;

contract Counter {
  uint256 private _value;
  
  event Increased(uint256 newValue);

  function increase() public {
      _value++;
      
      emit Increased(_value);
  }
  
  function getValue() public view returns (uint256) {
      return _value;
  }
}

Hi @pantsme

How is the thought process going? Do you have more questions?

1 Like