This guide will get you started with the governance process of deploying and instantiating CosmWasm smart contracts on Injective Mainnet.
Submit a Code Upload Proposal
In this section, you will learn how to submit a smart contract code proposal and vote for it.
Injective network participants can propose smart contracts deployments and vote in governance to enable them. The wasmd authorization settings are by on-chain governance, which means deployment of a contract is completely determined by governance. Because of this, a governance proposal is the first step to uploading contracts to Injective mainnet.
Sample usage of injectived to start a governance proposal to upload code to the chain:
The command injectived tx gov submit-proposal wasm-store submits a wasm binary proposal. The code will be deployed if the proposal is approved by governance.
Let’s go through two key flags instantiate-everybody and instantiate-only-address, which set instantiation permissions of the uploaded code. By default, everyone can instantiate the contract.
--instantiate-everybodyboolean# Everybody can instantiate a contract from the code, optional--instantiate-only-addressstring# Only this address can instantiate a contract instance from the code
Contract Instantiation (No Governance)
In most cases, you don’t need to push another governance proposal to instantiate. Simply instantiate with injectived tx wasm instantiate. You only need a governance proposal to upload a contract. You don’t need to go through governance to instantiate unless if the contract has the --instantiate-everybody flag to set to false, and --instantiate-only-address flag set to the governance module. The default value for --instantiate-everybody is true, and in this case you can permissionlessly instantiate via injectived tx wasm instantiate.
Flags:-a,--account-numberuintTheaccountnumberofthesigningaccount (offline modeonly)--adminstringAddressorkeynameofanadmin--amountstringCoinstosendtothecontractduringinstantiation--auxGenerateauxsignerdatainsteadofsendingatx-b,--broadcast-modestringTransactionbroadcastingmode (sync|async) (default"sync")--chain-idstringThenetworkchainID --dry-run ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it (when enabled, the local Keybase is not accessible)
--fee-granterstringFeegrantergrantsfeesforthetransaction--fee-payerstringFeepayerpaysfeesforthetransactioninsteadofdeductingfromthesigner--feesstringFeestopayalongwithtransaction; eg:10uatom--fromstringNameoraddressofprivatekeywithwhichtosign --gas string gas limit to set per-transaction; set to "auto" to calculate sufficient gas automatically. Note: "auto" option doesn't always report accurate results. Set a valid coin value to adjust the result. Can be used instead of "fees". (default 200000)
--gas-adjustment float adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored (default 1)
--gas-pricesstringGaspricesindecimalformattodeterminethetransactionfee (e.g. 0.1uatom) --generate-only Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase only accessed when providing a key name)
-h,--helphelpforinstantiate--keyring-backendstringSelectkeyring's backend (os|file|kwallet|pass|test|memory) (default "os") --keyring-dir string The client Keyring directory; if omitted, the default 'home' directory will be used --label string A human-readable name for this contract in lists --ledger Use a connected Ledger device --no-admin You must set this explicitly if you don'twantanadmin --node string <host>:<port> to tendermint rpc interface for this chain (default "tcp://localhost:26657")
--notestringNotetoaddadescriptiontothetransaction (previously --memo)--offlineOfflinemode (does notallowanyonlinefunctionality)-o,--outputstringOutputformat (text|json) (default"json")-s,--sequenceuintThesequencenumberofthesigningaccount (offline modeonly)--sign-modestringChoosesignmode (direct|amino-json|direct-aux), this is an advanced feature --timeout-height uint Set a block timeout height to prevent the tx from being committed past a certain height
--tip string Tip is the amount that is going to be transferred to the fee payer on the target chain. This flag is only valid when used with --aux, and is ignored if the target chain didn't enable the TipDecorator
-y,--yesSkiptxbroadcastingpromptconfirmation
An example injectived tx wasm instantiate can look something like this:
As mentioned above, contract instantiation permissions on mainnet depend on the flags used when uploading the code. By default, it is set to permissionless, as we can verify on the genesis wasmd Injective setup:
Flags:-a,--account-numberuintTheaccountnumberofthesigningaccount (offline modeonly)--adminstringAddressofanadmin--amountstringCoinstosendtothecontractduringinstantiation-b,--broadcast-modestringTransactionbroadcastingmode (sync|async|block) (default"sync")--depositstringDepositofproposal--descriptionstringDescriptionofproposal --dry-run ignore the --gas flag and perform a simulation of a transaction, but dont broadcast it (when enabled, the local Keybase is not accessible)
--fee-accountstringFeeaccountpaysfeesforthetransactioninsteadofdeductingfromthesigner--feesstringFeestopayalongwithtransaction; eg:10uatom--fromstringNameoraddressofprivatekeywithwhichtosign --gas string gas limit to set per-transaction; set to "auto" to calculate sufficient gas automatically (default 200000)
--gas-adjustment float adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored (default 1)
--gas-pricesstringGaspricesindecimalformattodeterminethetransactionfee (e.g. 0.1uatom) --generate-only Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase is not accessible)
-h,--helphelpforinstantiate-contract--keyring-backendstringSelectkeyringsbackend (os|file|kwallet|pass|test|memory) (default"os")--keyring-dirstringTheclientKeyringdirectory; ifomitted,thedefault'home'directorywillbeused--labelstringAhuman-readablenameforthiscontractinlists--ledgerUseaconnectedLedgerdevice--no-adminYoumustsetthisexplicitlyifyoudontwantanadmin --node string <host>:<port> to tendermint rpc interface for this chain (default "tcp://localhost:26657")
--notestringNotetoaddadescriptiontothetransaction (previously --memo)--offlineOfflinemode (does notallowanyonlinefunctionality-o,--outputstringOutputformat (text|json) (default"json")--proposalstringProposalfilepath (if thispathisgiven,otherproposalflagsareignored) --run-as string The address that pays the init funds. It is the creator of the contract and passed to the contract as sender on proposal execution
-s,--sequenceuintThesequencenumberofthesigningaccount (offline modeonly)--sign-modestringChoosesignmode (direct|amino-json), this is an advanced feature --timeout-height uint Set a block timeout height to prevent the tx from being committed past a certain height
--titlestringTitleofproposal --type string Permission of proposal, types: store-code/instantiate/migrate/update-admin/clear-admin/text/parameter_change/software_upgrade
-y,--yesSkiptxbroadcastingpromptconfirmation
Contract Migration
Migration is the process through which a given smart contract's code can be swapped out or 'upgraded'.
When instantiating a contract, there is an optional admin field that you can set. If it is left empty, the contract is immutable. If the admin is set (to an external account or governance contract), that account can trigger a migration. The admin can also reassign the admin role, or even make the contract fully immutable if desired. However, keep in mind that when migrating from an old contract to a new contract, the new contract needs to be aware of how the state was previously encoded.