|
|
2 years ago | |
|---|---|---|
| .. | ||
| contracts | d7e4e6ac01 Merge branch 'main' into cw_example | 2 years ago |
| devnet | d6e25d9209 Add pre-commit globally (#393) | 3 years ago |
| example | 1ecac75a9d add mocks | 2 years ago |
| tools | cdf99f4c60 Upgrade contract & fix deployment script (#447) | 2 years ago |
| .dockerignore | d6e25d9209 Add pre-commit globally (#393) | 3 years ago |
| .gitignore | 59ac319305 Abehjati/rename-terra-to-cw (#239) | 3 years ago |
| Cargo.lock | d0bf466cfe cleanup | 2 years ago |
| Cargo.toml | c79a4ba569 add cw example | 2 years ago |
| Dockerfile.build | 59ac319305 Abehjati/rename-terra-to-cw (#239) | 3 years ago |
| README.md | cdf99f4c60 Upgrade contract & fix deployment script (#447) | 2 years ago |
| build.sh | 59ac319305 Abehjati/rename-terra-to-cw (#239) | 3 years ago |
This directory contains the Pyth contract for CosmWasm and utilities to deploy it on CosmWasm chains.
Deploying the CosmWasm contract has two steps:
This directory includes a script to perform both steps. Read below for the details.
First, build the contracts within the current directory:
bash build.sh
This command will build and save the Pyth contract in the artifacts directory.
Then, to deploy the Pyth contract (pyth_cosmwasm.wasm), run the following command in the tools directory:
npm ci # Do it only once to install the required packages
npm run deploy-pyth -- --network testnet --artifact ../artifacts/pyth_cosmwasm.wasm --mnemonic "..."
If successful, this command will print something along the lines of:
Storing WASM: ../artifacts/pyth_cosmwasm.wasm (367689 bytes)
Deploy fee: 88446uluna
Code ID: 2435
If you do not pass any additional arguments to the script, it will only upload the code and return the code id. If you want to create a new contract or upgrade an existing contract you should pass more arguments that are described below.
If you want to instantiate a new contract after your deployment, pass --instantiate to the above command.
This command will upload the code and instantiates a new Pyth contract with the resulting code id:
npm run deploy-pyth -- --network testnet --artifact ../artifacts/pyth_cosmwasm.wasm --mnemonic "..." --instantiate
If successful, the output should look like so:
Storing WASM: ../artifacts/pyth_cosmwasm.wasm (183749 bytes)
Deploy fee: 44682uluna
Code ID: 53199
Instantiating a contract
Sleeping for 10 seconds for store transaction to finalize.
Instantiated Pyth at terra123456789yelw23uh22nadqlyjvtl7s5527er97 (0x0000000000000000000000001234567896267ee5479752a7d683e49317ff4294)
Deployed Pyth contract at terra123456789yelw23uh22nadqlyjvtl7s5527er97
If you want to upgrade an existing contract pass --migrate --contract terra123456xyzqwe.. to the above command.
This command will upload the code, and with the resulting code id, will migrate the existing contract to the new one:
npm run deploy-pyth -- --network testnet --artifact ../artifacts/pyth_cosmwasm.wasm --mnemonic "..." --migrate --contract "terra123..."
If successful, the output should look like so:
Storing WASM: ../artifacts/pyth_cosmwasm.wasm (183749 bytes)
Deploy fee: 44682uluna
Code ID: 53227
Sleeping for 10 seconds for store transaction to finalize.
Migrating contract terra1rhjej5gkyelw23uh22nadqlyjvtl7s5527er97 to 53227
Contract terra1rhjej5gkyelw23uh22nadqlyjvtl7s5527er97 code_id successfully updated to 53227
While running the instantiation/migration commands you might get the following errors:
You can rerun your command if you encounter any of the above errors. If an error occurs after the new code is uploaded, you can avoid re-uploading the code and use the uploaded code for instantiation/migration. You can use the printed code id in the logs
by passing --code-id <codeId> instead of --artifact. If you do so, the script will skip uploading the code and instantiate/migrate the contract with the given code id.
An example command using an existing code id looks like so:
npm run deploy-pyth -- --network testnet --code-id 50123 --mnemonic "..." --migrate --contract "terra123..."