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-runignorethe--gasflagandperformasimulationofatransaction,butdon't broadcast it (when enabled, the local Keybase is not accessible) --fee-granter string Fee granter grants fees for the transaction --fee-payer string Fee payer pays fees for the transaction instead of deducting from the signer --fees string Fees to pay along with transaction; eg: 10uatom --from string Name or address of private key with which to sign --gas string gas limit to set per-transaction; set to "auto" to calculate sufficient gas automatically. Note: "auto" option doesn'talwaysreportaccurateresults.Setavalidcoinvaluetoadjusttheresult.Canbeusedinsteadof"fees". (default 200000)--gas-adjustmentfloatadjustmentfactortobemultipliedagainsttheestimatereturnedbythetxsimulation; ifthegaslimitissetmanuallythisflagisignored (default 1)--gas-pricesstringGaspricesindecimalformattodeterminethetransactionfee (e.g. 0.1uatom)--generate-onlyBuildanunsignedtransactionandwriteittoSTDOUT (when enabled,thelocalKeybaseonlyaccessedwhenprovidingakeyname)-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--nodestring<host>:<port>totendermintrpcinterfaceforthischain (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-heightuintSetablocktimeoutheighttopreventthetxfrombeingcommittedpastacertainheight--tipstringTipistheamountthatisgoingtobetransferredtothefeepayeronthetargetchain.Thisflagisonlyvalidwhenusedwith--aux,andisignoredifthetargetchaindidn't enable the TipDecorator -y, --yes Skip tx broadcasting prompt confirmation
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:
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.