|
| 1 | +# Deploy a contract |
| 2 | +Instructions for Deploying ICS 100 (Atomic Swap) and ICS 101 (Interchain Swap) Cosmwasm Contracts: |
| 3 | + |
| 4 | +## Introduction: |
| 5 | +ICS 100 and ICS 101 are the first cross-chain DApps based on the IBC protocol. You can deploy them on any Cosmwasm blockchain, such as Injective, Osmosis, Neutron and more. They enable asset exchange among blockchains that have deployed this contract. |
| 6 | + |
| 7 | +## Deploy a contract |
| 8 | + |
| 9 | +> **NOTE** : |
| 10 | +> We are currently in the testing stage. Please deploy the contract only on the testnet and avoid doing so on any mainnet. |
| 11 | +
|
| 12 | +### Download contract |
| 13 | +First, You need to download the latest contract from [github release](https://github.com/sideprotocol/ibcswap-wasm/releases) |
| 14 | + |
| 15 | + |
| 16 | +### Deploy contract |
| 17 | +There are two ways to deploy contracts: |
| 18 | + |
| 19 | +### Deploy contract via the CLI |
| 20 | + |
| 21 | +> Here, we are using `sided` as an example to upload the contract to the SIDE blockchain. If you intend to upload it to other blockchains, you can easily substitute `sided` with the name of the respective binary. |
| 22 | +
|
| 23 | +1. Upload |
| 24 | + |
| 25 | +Upload the contract using the following command: |
| 26 | + |
| 27 | +```shell |
| 28 | +sided tx wasm store <CONRTACT_NAME.wasm> --chain-id="side-testnet-1" --from <KEY> -y --gas-prices=0.025uside --gas=auto --gas-adjustment 1.5 |
| 29 | +``` |
| 30 | +Subsequently, this will provide you with a transaction hash. Using this information, you should initiate a query to retrieve the code ID associated with the contract on the blockchain. |
| 31 | +```shell |
| 32 | +sided q tx 38330E909CD219B80927009DA37FD69D334D19B2AD4EC47456A24E85034F0085 --output=json |
| 33 | +``` |
| 34 | +This will provide transaction data, which includes the code ID of our contract. |
| 35 | + |
| 36 | +```json |
| 37 | +{ |
| 38 | + "height":"88588", |
| 39 | + "txhash":"A4F97683A5A648D5BDB355AD48C2380CD8C3406C40C5C97462134A642FEFD5D6", |
| 40 | + "codespace":"", |
| 41 | + "code":0, |
| 42 | + "data":"124E0A262F636F736D7761736D2E7761736D2E76312E4D736753746F7265436F6465526573706F6E73651224080212208998B8C5DA8803F0A1BF966C287342DB563AF38855E3D864B2E544B446935CA7", |
| 43 | + "raw_log":"[{\"msg_index\":0,\"events\":[{\"type\":\"message\",\"attributes\":[{\"key\":\"action\",\"value\":\"/cosmwasm.wasm.v1.MsgStoreCode\"},{\"key\":\"sender\",\"value\":\"side162ttnnflhvuazp42vxu5jf3fgxy750lrn3zrld\"},{\"key\":\"module\",\"value\":\"wasm\"}]},{\"type\":\"store_code\",\"attributes\":[{\"key\":\"code_checksum\",\"value\":\"8998b8c5da8803f0a1bf966c287342db563af38855e3d864b2e544b446935ca7\"},{\"key\":\"code_id\",\"value\":\"2\"}]}]}]", |
| 44 | + "logs":[ |
| 45 | + { |
| 46 | + "msg_index":0, |
| 47 | + "log":"", |
| 48 | + "events":[ |
| 49 | + { |
| 50 | + "type":"message", |
| 51 | + "attributes":[ |
| 52 | + { |
| 53 | + "key":"action", |
| 54 | + "value":"/cosmwasm.wasm.v1.MsgStoreCode" |
| 55 | + }, |
| 56 | + { |
| 57 | + "key":"sender", |
| 58 | + "value":"side162ttnnflhvuazp42vxu5jf3fgxy750lrn3zrld" |
| 59 | + }, |
| 60 | + { |
| 61 | + "key":"module", |
| 62 | + "value":"wasm" |
| 63 | + } |
| 64 | + ] |
| 65 | + }, |
| 66 | + { |
| 67 | + "type":"store_code", |
| 68 | + "attributes":[ |
| 69 | + { |
| 70 | + "key":"code_checksum", |
| 71 | + "value":"8998b8c5da8803f0a1bf966c287342db563af38855e3d864b2e544b446935ca7" |
| 72 | + }, |
| 73 | + { |
| 74 | + "key":"code_id", |
| 75 | + "value":"2" |
| 76 | + } |
| 77 | + ] |
| 78 | + } |
| 79 | + ] |
| 80 | + } |
| 81 | + ], |
| 82 | + "info":"", |
| 83 | + "gas_wanted":"62244349", |
| 84 | + "gas_used":"41511708", |
| 85 | + "tx":{ |
| 86 | + "@type":"/cosmos.tx.v1beta1.Tx", |
| 87 | + "body":{ |
| 88 | + "messages":[ |
| 89 | + { |
| 90 | + "@type":"/cosmwasm.wasm.v1.MsgStoreCode", |
| 91 | + "sender":"side162ttnnflhvuazp42vxu5jf3fgxy750lrn3zrld", |
| 92 | + "instantiate_permission":null |
| 93 | + } |
| 94 | + ], |
| 95 | + "memo":"", |
| 96 | + "timeout_height":"0", |
| 97 | + "extension_options":[ |
| 98 | + |
| 99 | + ], |
| 100 | + "non_critical_extension_options":[ |
| 101 | + |
| 102 | + ] |
| 103 | + }, |
| 104 | + "auth_info":{ |
| 105 | + "signer_infos":[ |
| 106 | + { |
| 107 | + "public_key":{ |
| 108 | + "@type":"/cosmos.crypto.secp256k1.PubKey", |
| 109 | + "key":"ArT6KLBCAim72FU76qqFuJvDE93M6UsAuLIPWo6artaO" |
| 110 | + }, |
| 111 | + "mode_info":{ |
| 112 | + "single":{ |
| 113 | + "mode":"SIGN_MODE_DIRECT" |
| 114 | + } |
| 115 | + }, |
| 116 | + "sequence":"5" |
| 117 | + } |
| 118 | + ], |
| 119 | + "fee":{ |
| 120 | + "amount":[ |
| 121 | + { |
| 122 | + "denom":"uside", |
| 123 | + "amount":"1556109" |
| 124 | + } |
| 125 | + ], |
| 126 | + "gas_limit":"62244349", |
| 127 | + "payer":"", |
| 128 | + "granter":"" |
| 129 | + }, |
| 130 | + "tip":null |
| 131 | + }, |
| 132 | + "signatures":[ |
| 133 | + "htd8LvE8rA5MS8O3yBsOoIkN5YeqbTOJbsisvFFZVk4KM7rzvlYxBpLwhMRxRSHjj0IwNBoMp6RpibEK02fM9g==" |
| 134 | + ] |
| 135 | + }, |
| 136 | + "timestamp":"2023-08-27T06:57:12Z", |
| 137 | + "events":[ |
| 138 | + { |
| 139 | + "type":"coin_spent", |
| 140 | + "attributes":[ |
| 141 | + { |
| 142 | + "key":"spender", |
| 143 | + "value":"side162ttnnflhvuazp42vxu5jf3fgxy750lrn3zrld", |
| 144 | + "index":true |
| 145 | + }, |
| 146 | + { |
| 147 | + "key":"amount", |
| 148 | + "value":"1556109uside", |
| 149 | + "index":true |
| 150 | + } |
| 151 | + ] |
| 152 | + }, |
| 153 | + { |
| 154 | + "type":"coin_received", |
| 155 | + "attributes":[ |
| 156 | + { |
| 157 | + "key":"receiver", |
| 158 | + "value":"side17xpfvakm2amg962yls6f84z3kell8c5lyc7646", |
| 159 | + "index":true |
| 160 | + }, |
| 161 | + { |
| 162 | + "key":"amount", |
| 163 | + "value":"1556109uside", |
| 164 | + "index":true |
| 165 | + } |
| 166 | + ] |
| 167 | + }, |
| 168 | + { |
| 169 | + "type":"transfer", |
| 170 | + "attributes":[ |
| 171 | + { |
| 172 | + "key":"recipient", |
| 173 | + "value":"side17xpfvakm2amg962yls6f84z3kell8c5lyc7646", |
| 174 | + "index":true |
| 175 | + }, |
| 176 | + { |
| 177 | + "key":"sender", |
| 178 | + "value":"side162ttnnflhvuazp42vxu5jf3fgxy750lrn3zrld", |
| 179 | + "index":true |
| 180 | + }, |
| 181 | + { |
| 182 | + "key":"amount", |
| 183 | + "value":"1556109uside", |
| 184 | + "index":true |
| 185 | + } |
| 186 | + ] |
| 187 | + }, |
| 188 | + { |
| 189 | + "type":"message", |
| 190 | + "attributes":[ |
| 191 | + { |
| 192 | + "key":"sender", |
| 193 | + "value":"side162ttnnflhvuazp42vxu5jf3fgxy750lrn3zrld", |
| 194 | + "index":true |
| 195 | + } |
| 196 | + ] |
| 197 | + }, |
| 198 | + { |
| 199 | + "type":"tx", |
| 200 | + "attributes":[ |
| 201 | + { |
| 202 | + "key":"fee", |
| 203 | + "value":"1556109uside", |
| 204 | + "index":true |
| 205 | + }, |
| 206 | + { |
| 207 | + "key":"fee_payer", |
| 208 | + "value":"side162ttnnflhvuazp42vxu5jf3fgxy750lrn3zrld", |
| 209 | + "index":true |
| 210 | + } |
| 211 | + ] |
| 212 | + }, |
| 213 | + { |
| 214 | + "type":"tx", |
| 215 | + "attributes":[ |
| 216 | + { |
| 217 | + "key":"acc_seq", |
| 218 | + "value":"side162ttnnflhvuazp42vxu5jf3fgxy750lrn3zrld/5", |
| 219 | + "index":true |
| 220 | + } |
| 221 | + ] |
| 222 | + }, |
| 223 | + { |
| 224 | + "type":"tx", |
| 225 | + "attributes":[ |
| 226 | + { |
| 227 | + "key":"signature", |
| 228 | + "value":"htd8LvE8rA5MS8O3yBsOoIkN5YeqbTOJbsisvFFZVk4KM7rzvlYxBpLwhMRxRSHjj0IwNBoMp6RpibEK02fM9g==", |
| 229 | + "index":true |
| 230 | + } |
| 231 | + ] |
| 232 | + }, |
| 233 | + { |
| 234 | + "type":"message", |
| 235 | + "attributes":[ |
| 236 | + { |
| 237 | + "key":"action", |
| 238 | + "value":"/cosmwasm.wasm.v1.MsgStoreCode", |
| 239 | + "index":true |
| 240 | + }, |
| 241 | + { |
| 242 | + "key":"sender", |
| 243 | + "value":"side162ttnnflhvuazp42vxu5jf3fgxy750lrn3zrld", |
| 244 | + "index":true |
| 245 | + }, |
| 246 | + { |
| 247 | + "key":"module", |
| 248 | + "value":"wasm", |
| 249 | + "index":true |
| 250 | + } |
| 251 | + ] |
| 252 | + }, |
| 253 | + { |
| 254 | + "type":"store_code", |
| 255 | + "attributes":[ |
| 256 | + { |
| 257 | + "key":"code_checksum", |
| 258 | + "value":"8998b8c5da8803f0a1bf966c287342db563af38855e3d864b2e544b446935ca7", |
| 259 | + "index":true |
| 260 | + }, |
| 261 | + { |
| 262 | + "key":"code_id", |
| 263 | + "value":"2", |
| 264 | + "index":true |
| 265 | + } |
| 266 | + ] |
| 267 | + } |
| 268 | + ] |
| 269 | +} |
| 270 | +``` |
| 271 | +2. Instantiate |
| 272 | + |
| 273 | +With the code now deployed on the chain, we can proceed to execute the logic to establish our own instance of the contract under our control. This will generate a distinct contract address that others can engage with based on the contract's logic. |
| 274 | +```shell |
| 275 | +CODE_ID = 123 |
| 276 | +side tx wasm instantiate $CODE_ID {"TOKEN_ID": 1}\ |
| 277 | + --from=<KEY> -y \ |
| 278 | + --admin=<ADDRESS_OF_ADMIN> |
| 279 | + --label "some-contract" \ |
| 280 | + --broadcast-mode=block \ |
| 281 | + --chain-id=side-testnet-1 \ |
| 282 | + --gas-prices=0.025ujunox \ |
| 283 | + --gas=auto \ |
| 284 | + --gas-adjustment=1 |
| 285 | +``` |
| 286 | + |
| 287 | +3. Query My Contracts address |
| 288 | + |
| 289 | +You can query all your Instantiated contracts |
| 290 | +```shell |
| 291 | +sided q wasm list-contracts-by-creator side1m8mma95ta2zajqtmfp5c5y3wgeyqzcrc2tddvx |
| 292 | +contract_addresses: |
| 293 | +- side14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9scdth4q |
| 294 | +pagination: |
| 295 | + next_key: null |
| 296 | + total: "0" |
| 297 | + |
| 298 | +``` |
| 299 | + |
| 300 | +In this example, the contract address is "side14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9scdth4q". |
| 301 | + |
| 302 | +4. Query Contract Info |
| 303 | +```shell |
| 304 | +sided q wasm contract side14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9scdth4q |
| 305 | +address: side14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9scdth4q |
| 306 | +contract_info: |
| 307 | + admin: side1m8mma95ta2zajqtmfp5c5y3wgeyqzcrc2tddvx |
| 308 | + code_id: "1" |
| 309 | + created: |
| 310 | + block_height: "38071" |
| 311 | + tx_index: "0" |
| 312 | + creator: side1m8mma95ta2zajqtmfp5c5y3wgeyqzcrc2tddvx |
| 313 | + extension: null |
| 314 | + ibc_port_id: wasm.side14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9scdth4q |
| 315 | + label: cross chain swap |
| 316 | +``` |
| 317 | + |
| 318 | +**Note** : The `ibc_port_id` will be utilized by the relayer to establish an IBC connection with the contracts deployed on other blockchains. |
| 319 | + |
| 320 | +### Deploy contract on ping.pub (Recommended) |
| 321 | + |
| 322 | +Ping Dashboard offers a user-friendly web UI for interacting with WASM contracts, making it much easier for you to perform such tasks. |
| 323 | + |
| 324 | +1. Access Ping Dashboard for the testnet. |
| 325 | + |
| 326 | +Open either Google Chrome or Mozilla Firefox web browser. In the address bar, type "[https://testnet.ping.pub]()". Please make sure you have the Keplr Wallet Extension installed, as it's used for signing transactions. |
| 327 | + |
| 328 | + |
| 329 | + |
| 330 | +You can choose any CosmWasm blockchain listed on this homepage to deploy a contract. We are using SIDE as an example. |
| 331 | + |
| 332 | +2. Upload contract on Cosmwasm Module |
| 333 | + |
| 334 | +You can click the buttons in the order indicated on the screenshot. |
| 335 | + |
| 336 | +<img width="1434" alt="upload" src="https://github.com/sideprotocol/testnet/assets/2882920/427131eb-db48-446c-be04-6ab79872d37e"> |
| 337 | + |
| 338 | +Once the transaction has succeeded, you will be able to see your code on the wasm code list. Please note that you might need to reload the page occasionally. |
| 339 | + |
| 340 | +3. Instantiate Contract |
| 341 | + |
| 342 | +To instantiate a contract, click on the code hash to access the contract list page. There, you will see: |
| 343 | +<img width="1435" alt="image" src="https://github.com/sideprotocol/testnet/assets/2882920/7e074aa7-7f2d-410e-b0b6-b5e4380f40d4"> |
| 344 | + |
| 345 | +You can click `Instantiate Contract` |
| 346 | +<img width="1433" alt="image" src="https://github.com/sideprotocol/testnet/assets/2882920/2d8e8482-cb51-4f12-b262-78c81a56d061"> |
| 347 | + |
| 348 | +If you see a result like this, it indicates that you have successfully instantiated the code into a contract. |
| 349 | + |
| 350 | +<img width="1430" alt="image" src="https://github.com/sideprotocol/testnet/assets/2882920/21348c85-29d1-4fb7-bccc-6c5c155c43dc"> |
| 351 | + |
| 352 | +4. Query Contract State |
| 353 | + |
| 354 | +You can now query various states of the contract: |
| 355 | + |
| 356 | +<img width="1433" alt="image" src="https://github.com/sideprotocol/testnet/assets/2882920/eb84c592-e188-4dd5-92ae-523fdbec5584"> |
| 357 | + |
| 358 | +## Next |
| 359 | + |
| 360 | +You can now set up a relayer to connect to another blockchain. |
| 361 | + |
| 362 | + |
0 commit comments