{"id":3707,"date":"2022-12-15T14:40:20","date_gmt":"2022-12-15T14:40:20","guid":{"rendered":"https:\/\/metaschool.so\/articles\/?p=3707"},"modified":"2023-08-31T10:27:02","modified_gmt":"2023-08-31T10:27:02","slug":"upgrade-contracts-openzeppelin-upgradable-plugin","status":"publish","type":"post","link":"https:\/\/metaschool.so\/articles\/upgrade-contracts-openzeppelin-upgradable-plugin\/","title":{"rendered":"How to upgrade contracts with OpenZeppelin Upgradable Plugin"},"content":{"rendered":"\n<p>To upgrade a smart contract using the <a href=\"https:\/\/metaschool.so\/articles\/what-is-openzeppelin\/\">OpenZeppelin<\/a> Upgradable Plugin, you will first need to ensure that you have the latest version of the OpenZeppelin CLI installed on your computer. You can do this by running the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code has-nv-site-bg-background-color has-background\"><code>npm install -g @openzeppelin\/cli<\/code><\/pre>\n\n\n\n<p>Once you have the <a href=\"https:\/\/docs.openzeppelin.com\/cli\/2.7\/\" target=\"_blank\" rel=\"noreferrer noopener\">OpenZeppelin CLI<\/a> installed, you can create a new project using the <code>openzeppelin init<\/code> command. This will initialize a new project in the current directory and install the necessary dependencies, including the Upgradable plugin.<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffc Next, you can create a new upgradable smart contract by running the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-nv-site-bg-background-color has-background\">Copy code<code>openzeppelin create MyContract --kind upgradable\n<\/code><\/pre>\n\n\n\n<p>This will create a new file called <code>MyContract.sol<\/code> in the <code>contracts<\/code> directory of your project. This file will contain the code for your upgradable smart contract, including a <code>Proxy<\/code> contract that will be used to upgrade the contract in the future.<\/p>\n\n\n\n<p>Once you have written the code for your <a href=\"https:\/\/metaschool.so\/courses\/writing-your-first-hello-world-contract-in-solidity?ref=Articles&amp;utm_source=Blog_Organic\" target=\"_blank\" rel=\"noreferrer noopener\">smart contract<\/a>, you can compile and deploy it to the blockchain using the <code>openzeppelin deploy<\/code> command. This will create a new instance of your contract on the blockchain and return its address.<\/p>\n\n\n\n<p>To upgrade your contract, you can use the <code>openzeppelin upgrade<\/code> command. This will create a new instance of your contract with the updated code, and point the proxy contract to the new instance. <\/p>\n\n\n\n<p>This allows you to make changes to your smart contract&#8217;s code and deploy them to the blockchain without having to redeploy the entire contract.<\/p>\n\n\n\n<p>It&#8217;s important to note that upgrading a contract using the OpenZeppelin Upgradable plugin is a complex process, and it&#8217;s recommended that you have a good understanding of <a href=\"https:\/\/metaschool.so\/courses\/how-to-write-a-smart-contract-and-mint-elon-musk-nft-on-opensea?ref=Articles&amp;utm_source=Blog_Organic\" target=\"_blank\" rel=\"noreferrer noopener\">smart contract development<\/a> and deployment before attempting to do so. If you&#8217;re not sure how to proceed, it&#8217;s a good idea to seek help from experienced smart contract developers or consult the OpenZeppelin documentation for more information.<\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":3710,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","footnotes":""},"categories":[292],"tags":[36],"class_list":["post-3707","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-answers","tag-blockchain-applications"],"_links":{"self":[{"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/posts\/3707","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/comments?post=3707"}],"version-history":[{"count":7,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/posts\/3707\/revisions"}],"predecessor-version":[{"id":6822,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/posts\/3707\/revisions\/6822"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/media\/3710"}],"wp:attachment":[{"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/media?parent=3707"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/categories?post=3707"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/tags?post=3707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}