1 stable release

3.0.0 Mar 23, 2022

#11 in #delegates

MIT license

89KB
111 lines

Delegator Smart Contract

The delegator smart contract is our showcase for executing other smart contracts on-chain.

It consists in total of 4 different smart contract:

  • Delegator (root): Delegates calls either to the Adder or Subber smart contract
  • Adder: Increases a value in the Accumulator smart contract
  • Subber: Decreases a value in the Accumulator smart contract
  • Accumulator: Owns a simple i32 value that can be incremented or decremented

In order to test this bundle of smart contracts you need to execute the following steps.

You can upload the contracts using our Contracts UI. If you want to test it locally, our substrate-contracts-node is an easy way to get a local smart contract chain running.

  1. Compile all contracts using the ./build-all.sh script. You will receive the respective .contract bundles for all the smart contracts in the target/ink/ folder:

    • target/ink/delegator.contract
    • target/ink/adder/adder.contract
    • target/ink/subber/subber.contract
    • target/ink/accumulator/accumulator.contract
  2. Upload the .contract bundle of Accumulator, Adder and Subber to the chain.

  3. Note down the respective code hashes of the uploaded contracts. You can copy the contract hashes from the page of uploaded contracts:

  4. Instantiate the Delegator smart contract given all of the code hashes and a starting value. Make sure the endowment is big enough (if you're using our substrate-contracts-node it's 1000000). The Delegator smart contract will take over the work of instantiating the other smart contracts for you.

  5. Now you are able to run the operations provided by the Delegator smart contract. Namely delegate to delegate the call to either the Adder or the Subber to either increase or decrease the value stored in the Accumulator smart contract respectively and switch to switch the currently delegated-to smart contract. The initial delegated-to smart contract is the Adder.


    __Note:__
    Depending on your Substrate version you might encounter a bug with the pre-filled gas estimation of the UI and get the error ExtrinsicFailed: OutOfGas. As a workaround set the maximum allowed gas manually (e.g. to 5000).

Dependencies

~5–7MB
~128K SLoC