github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/wasm/README.md (about)

     1  # Wasm Module
     2  
     3  This should be a brief overview of the functionality
     4  
     5  ## Configuration
     6  
     7  You can add the following section to `config/app.toml`:
     8  
     9  ```toml
    10  [wasm]
    11  # This is the maximum sdk gas (wasm and storage) that we allow for any x/wasm "smart" queries
    12  query_gas_limit = 300000
    13  # This defines the memory size for Wasm modules that we can keep cached to speed-up instantiation
    14  # The value is in MiB not bytes
    15  memory_cache_size = 300
    16  ```
    17  
    18  The values can also be set via CLI flags on with the `start` command:
    19  ```shell script
    20  --wasm.memory_cache_size uint32     Sets the size in MiB (NOT bytes) of an in-memory cache for wasm modules. Set to 0 to disable. (default 100)
    21  --wasm.query_gas_limit uint         Set the max gas that can be spent on executing a query with a Wasm contract (default 3000000)
    22  ```
    23  
    24  ## Events
    25  
    26  A number of events are returned to allow good indexing of the transactions from smart contracts.
    27  
    28  Every call to Instantiate or Execute will be tagged with the info on the contract that was executed and who executed it.
    29  It should look something like this (with different addresses). The module is always `wasm`, and `code_id` is only present
    30  when Instantiating a contract, so you can subscribe to new instances, it is omitted on Execute. There is also an `action` tag
    31  which is auto-added by the Cosmos SDK and has a value of either `store-code`, `instantiate` or `execute` depending on which message
    32  was sent:
    33  
    34  ```json
    35  {
    36      "Type": "message",
    37      "Attr": [
    38          {
    39              "key": "module",
    40              "value": "wasm"
    41          },
    42          {
    43              "key": "action",
    44              "value": "instantiate"
    45          },
    46          {
    47              "key": "signer",
    48              "value": "cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x"
    49          },
    50          {
    51              "key": "code_id",
    52              "value": "1"
    53          },
    54          {
    55              "key": "_contract_address",
    56              "value": "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr"
    57          }
    58      ]
    59  }
    60  ```
    61  
    62  If any funds were transferred to the contract as part of the message, or if the contract released funds as part of it's executions,
    63  it will receive the typical events associated with sending tokens from bank. In this case, we instantiate the contract and
    64  provide a initial balance in the same `MsgInstantiateContract`. We see the following events in addition to the above one:
    65  
    66  ```json
    67  [
    68      {
    69          "Type": "transfer",
    70          "Attr": [
    71              {
    72                  "key": "recipient",
    73                  "value": "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr"
    74              },
    75              {
    76                  "key": "sender",
    77                  "value": "cosmos1ffnqn02ft2psvyv4dyr56nnv6plllf9pm2kpmv"
    78              },
    79              {
    80                  "key": "amount",
    81                  "value": "100000denom"
    82              }
    83          ]
    84      }
    85  ]
    86  ```
    87  
    88  Finally, the contract itself can emit a "custom event" on Execute only (not on Init).
    89  There is one event per contract, so if one contract calls a second contract, you may receive
    90  one event for the original contract and one for the re-invoked contract. All attributes from the contract are passed through verbatim,
    91  and we add a `_contract_address` attribute that contains the actual contract that emitted that event.
    92  Here is an example from the escrow contract successfully releasing funds to the destination address:
    93  
    94  ```json
    95  {
    96      "Type": "wasm",
    97      "Attr": [
    98          {
    99              "key": "_contract_address",
   100              "value": "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr"
   101          },
   102          {
   103              "key": "action",
   104              "value": "release"
   105          },
   106          {
   107              "key": "destination",
   108              "value": "cosmos14k7v7ms4jxkk2etmg9gljxjm4ru3qjdugfsflq"
   109          }
   110      ]
   111  }
   112  ```
   113  
   114  ### Pulling this all together
   115  
   116  We will invoke an escrow contract to release to the designated beneficiary.
   117  The escrow was previously loaded with `100000denom` (from the above example).
   118  In this transaction, we send `5000denom` along with the `MsgExecuteContract`
   119  and the contract releases the entire funds (`105000denom`) to the beneficiary.
   120  
   121  We will see all the following events, where you should be able to reconstruct the actions
   122  (remember there are two events for each transfer). We see (1) the initial transfer of funds
   123  to the contract, (2) the contract custom event that it released funds (3) the transfer of funds
   124  from the contract to the beneficiary and (4) the generic x/wasm event stating that the contract
   125  was executed (which always appears, while 2 is optional and has information as reliable as the contract):
   126  
   127  ```json
   128  [
   129      {
   130          "Type": "transfer",
   131          "Attr": [
   132              {
   133                  "key": "recipient",
   134                  "value": "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr"
   135              },
   136              {
   137                  "key": "sender",
   138                  "value": "cosmos1zm074khx32hqy20hlshlsd423n07pwlu9cpt37"
   139              },
   140              {
   141                  "key": "amount",
   142                  "value": "5000denom"
   143              }
   144          ]
   145      },
   146      {
   147          "Type": "wasm",
   148          "Attr": [
   149              {
   150                  "key": "_contract_address",
   151                  "value": "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr"
   152              },
   153              {
   154                  "key": "action",
   155                  "value": "release"
   156              },
   157              {
   158                  "key": "destination",
   159                  "value": "cosmos14k7v7ms4jxkk2etmg9gljxjm4ru3qjdugfsflq"
   160              }
   161          ]
   162      },
   163      {
   164          "Type": "transfer",
   165          "Attr": [
   166              {
   167                  "key": "recipient",
   168                  "value": "cosmos14k7v7ms4jxkk2etmg9gljxjm4ru3qjdugfsflq"
   169              },
   170              {
   171                  "key": "sender",
   172                  "value": "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr"
   173              },
   174              {
   175                  "key": "amount",
   176                  "value": "105000denom"
   177              }
   178          ]
   179      },
   180      {
   181          "Type": "message",
   182          "Attr": [
   183              {
   184                  "key": "module",
   185                  "value": "wasm"
   186              },
   187              {
   188                  "key": "action",
   189                  "value": "execute"
   190              },
   191              {
   192                  "key": "signer",
   193                  "value": "cosmos1zm074khx32hqy20hlshlsd423n07pwlu9cpt37"
   194              },
   195              {
   196                  "key": "_contract_address",
   197                  "value": "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr"
   198              }
   199          ]
   200      }
   201  ]
   202  ```
   203  
   204  A note on this format. This is what we return from our module. However, it seems to me that many events with the same `Type`
   205  get merged together somewhere along the stack, so in this case, you *may* end up with one "transfer" event with the info for
   206  both transfers. Double check when evaluating the event logs, I will document better with more experience, especially when I
   207  find out the entire path for the events.
   208  
   209  ## Messages
   210  
   211  TODO
   212  
   213  ## CLI
   214  
   215  TODO - working, but not the nicest interface (json + bash = bleh). Use to upload, but I suggest to focus on frontend / js tooling
   216  
   217  ## Rest
   218  
   219  TODO - main supported interface, under rapid change