<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Cormac</title>
    <description>The latest articles on DEV Community by Cormac (@cormacncheese).</description>
    <link>https://dev.to/cormacncheese</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F805821%2Fb241356f-8962-4f51-a893-fe855341b136.jpg</url>
      <title>DEV Community: Cormac</title>
      <link>https://dev.to/cormacncheese</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cormacncheese"/>
    <language>en</language>
    <item>
      <title>How to Reconnect to Process logs on Ubuntu</title>
      <dc:creator>Cormac</dc:creator>
      <pubDate>Tue, 07 Jun 2022 22:05:09 +0000</pubDate>
      <link>https://dev.to/cormacncheese/how-to-reconnect-to-process-logs-on-ubuntu-3o0j</link>
      <guid>https://dev.to/cormacncheese/how-to-reconnect-to-process-logs-on-ubuntu-3o0j</guid>
      <description>&lt;p&gt;Running continuous processes or functions on a virtual machine is essential for any large development process.&lt;/p&gt;

&lt;p&gt;Here's how to continuously run a process on Ubuntu, disconnect and then reconnect to access a process' logs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1) Start &lt;code&gt;screen&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;This might be already installed, check with: &lt;code&gt;screen --version&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If not, install with one of these commands (OS specific)&lt;/p&gt;

&lt;p&gt;yum install screen&lt;br&gt;
apt install screen&lt;/p&gt;

&lt;p&gt;Open a screen session: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;screen&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.gnu.org/software/screen/manual/screen.html"&gt;Screen User Manual&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2) Run your program with &lt;code&gt;&amp;amp;&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;I'm running a validator in a GCP ubuntu virtual machine so my start command looks like:&lt;br&gt;
&lt;code&gt;sudo mortar server --data-dir ./data-dir --chain genesis.json --libp2p 0.0.0.0:1478 --nat IP-ADDRESS --seal --price-limit 1 &amp;amp;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Just make sure to add &lt;code&gt;&amp;amp;&lt;/code&gt; to the end of whatever command you use. This is let the program to keep running even after you quit the shell session.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3) Disconnect your SSH session
&lt;/h2&gt;

&lt;p&gt;You can do this by closing the shell window&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4) Reconnect
&lt;/h2&gt;

&lt;p&gt;Resume screen session: &lt;code&gt;screen -r&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You should now see the output of the process logs in real time&lt;/p&gt;

</description>
      <category>devops</category>
      <category>ubuntu</category>
      <category>blockchain</category>
    </item>
    <item>
      <title>How to Manage Multiple Github Accounts</title>
      <dc:creator>Cormac</dc:creator>
      <pubDate>Tue, 07 Jun 2022 19:04:45 +0000</pubDate>
      <link>https://dev.to/cormacncheese/how-to-manage-multiple-github-accounts-37l1</link>
      <guid>https://dev.to/cormacncheese/how-to-manage-multiple-github-accounts-37l1</guid>
      <description>&lt;p&gt;If you work for a company and code on the side you may need to manage multiple Github accounts from the same device. &lt;/p&gt;

&lt;p&gt;Here's how to push from two different Github accounts locally&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1) Create SSH keys
&lt;/h2&gt;

&lt;p&gt;For each SSH key pairs:&lt;br&gt;
&lt;code&gt;run ssh-keygen -t rsa -b 4096 -C "your_email@example.com"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You'll be prompted: "Enter a file in which to save the key" so make sure to use a unique name like "company" or "personal".&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 2) Add public key to Github
&lt;/h2&gt;

&lt;p&gt;Follow &lt;a href="https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/"&gt;these steps&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Step 3) Create an ssh config file&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;code&gt;cd ~/.ssh&lt;/code&gt;&lt;br&gt;
&lt;code&gt;touch config&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Enter something like this making sure to save after:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#personal account
Host github.com-personal
   HostName github.com
   User git
   IdentityFile ~/.ssh/personal
   IdentitiesOnly yes

#user2 account
Host github.com-company
   HostName github.com
   User git
   IdentityFile ~/.ssh/company
   IdentitiesOnly yes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 4) Clone Repo
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;git clone git@github.com-company:REPOSITORY_NAME.git&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5) Edit config
&lt;/h2&gt;

&lt;p&gt;You'll need to do this for each repo&lt;/p&gt;

&lt;p&gt;Open up local git config using git config --local -e and add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[user]
    name = company
    email = name@company.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;type &lt;code&gt;:wq&lt;/code&gt; and &lt;strong&gt;&lt;em&gt;enter&lt;/em&gt;&lt;/strong&gt; to save and quit&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6) Confirm your remote url
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;git remote set-url origin git@github-comcompany:REPOSITORY_NAME.git&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 7) Git add commit and push
&lt;/h2&gt;

&lt;p&gt;Now you can git actions (pull/push/fetch...etc) all you like!&lt;/p&gt;

&lt;p&gt;Resources:&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=R5yS23LKr04"&gt;https://www.youtube.com/watch?v=R5yS23LKr04&lt;/a&gt;&lt;br&gt;
&lt;a href="https://gist.github.com/Jonalogy/54091c98946cfe4f8cdab2bea79430f9"&gt;https://gist.github.com/Jonalogy/54091c98946cfe4f8cdab2bea79430f9&lt;/a&gt; &lt;/p&gt;

</description>
      <category>github</category>
      <category>programming</category>
      <category>devops</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>How to Debug Reactjs App running on iPhone in Safari</title>
      <dc:creator>Cormac</dc:creator>
      <pubDate>Fri, 27 May 2022 17:03:27 +0000</pubDate>
      <link>https://dev.to/cormacncheese/debug-reactjs-app-running-on-iphone-in-safari-482h</link>
      <guid>https://dev.to/cormacncheese/debug-reactjs-app-running-on-iphone-in-safari-482h</guid>
      <description>&lt;p&gt;Sometimes Chrome and Safari dev tools mobile view for a web app aren't perfectly accurate so it's important to test it on a real mobile device.&lt;/p&gt;

&lt;p&gt;This is how to debug a Reactjs application running on an iPhone.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1) Start your application locally
&lt;/h2&gt;

&lt;p&gt;This usually entails running &lt;code&gt;yarn start&lt;/code&gt; or &lt;code&gt;next dev&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2) Start ngrok
&lt;/h2&gt;

&lt;p&gt;This allows you to access your local app on your phone and edit files in real-time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3) Allow Web Inspector on iPhone
&lt;/h2&gt;

&lt;p&gt;This can be turned on in Settings &amp;gt; Safari &amp;gt; Advanced&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5akxBUGF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2r2mdfxt0u9z7yp0chdg.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5akxBUGF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2r2mdfxt0u9z7yp0chdg.jpg" alt="Image description" width="880" height="1754"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4) Open Reactjs app on Safari
&lt;/h2&gt;

&lt;p&gt;Instead of using &lt;a href="http://localhost:3000/"&gt;http://localhost:3000/&lt;/a&gt; open your app using the ngrok url in Safari on your phone&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KCJ0EbFH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/es0sthdg6pz6jzp6pfpq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KCJ0EbFH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/es0sthdg6pz6jzp6pfpq.png" alt="Image description" width="880" height="243"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5) Open Dev Tools in Safari
&lt;/h2&gt;

&lt;p&gt;If you've correctly followed the previous steps now you can open Safari on your laptop by opening Safari &amp;gt; Develop &amp;gt; Device &amp;gt; ngrok&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aiML_LQK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rg7xq4827xhq1c0y4dpz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aiML_LQK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rg7xq4827xhq1c0y4dpz.png" alt="Image description" width="880" height="268"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6) Debug!
&lt;/h2&gt;

&lt;p&gt;With your React app running locally from Safari on your phone and dev tools opened in Safari you can now debug your app with the same visibility you could from Chrome dev tools.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iQeqgm37--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p0h3j303n546e1wwyezs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iQeqgm37--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p0h3j303n546e1wwyezs.png" alt="Image description" width="880" height="576"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Dockerize a Next.js app</title>
      <dc:creator>Cormac</dc:creator>
      <pubDate>Sat, 14 May 2022 18:21:36 +0000</pubDate>
      <link>https://dev.to/cormacncheese/how-to-dockerize-a-nextjs-app-3g5g</link>
      <guid>https://dev.to/cormacncheese/how-to-dockerize-a-nextjs-app-3g5g</guid>
      <description>&lt;p&gt;Use this example dockerfile to dockerize and build your Next.js app as an image.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Node version
FROM node:14-alpine as build

RUN apk update
RUN apk --no-cache --virtual build-dependencies add \
    jpeg-dev \
    cairo-dev \
    giflib-dev \
    pango-dev \
    python3 \
    make \
    g++ 


# Set the working directory
WORKDIR /app

# Add the source code to app
COPY . /app

# Install all the dependencies
RUN yarn install --frozen-lockfile

# Generate the build of the application
RUN yarn build

# Production image, copy all the files and run next
FROM node:14-alpine AS runner
WORKDIR /app

RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001

# Copy the build output to replace the default nginx contents.
# COPY --from=build /app/next.config.js ./
COPY --from=build /app/public ./public
COPY --from=build --chown=nextjs:nodejs /app/.next ./.next
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/package.json ./package.json

USER root

EXPOSE 3000

CMD ["yarn", "start"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then run the following to build it:&lt;br&gt;
&lt;code&gt;docker build --no-cache -t latest .&lt;/code&gt;&lt;br&gt;
&lt;code&gt;docker run latest&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can now use this to push to Google Cloud Container Registry &lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to send Ether or Matic using Ethers</title>
      <dc:creator>Cormac</dc:creator>
      <pubDate>Sat, 14 May 2022 16:57:18 +0000</pubDate>
      <link>https://dev.to/cormacncheese/how-to-send-ether-or-matic-using-ethers-4fjo</link>
      <guid>https://dev.to/cormacncheese/how-to-send-ether-or-matic-using-ethers-4fjo</guid>
      <description>&lt;p&gt;If you're building a dapp you'll probably need to implement a solution for users to send tokens to one another.&lt;/p&gt;

&lt;p&gt;Here's how to send ethers or any ERC-20 token from the frontend using ethers and web3.&lt;/p&gt;

&lt;p&gt;First we'll need these three libraries: &lt;code&gt;web3&lt;/code&gt;, &lt;code&gt;web3modal&lt;/code&gt; and &lt;code&gt;ethers&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;yarn add ethers web3 web3modal&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then we need to request to connect to Metamask or any other Ethereum web wallet a user is using.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const connectToMetamask = async () =&amp;gt; {
    const web3Modal = new Web3Modal()
    const connection = await web3Modal.connect()
    const provider = new ethers.providers.Web3Provider(connection)
    const signer = provider.getSigner()
    const address = await signer.getAddress()
    if (!address || !signer || !provider) {
      console.log("ERROR couldn't connect to metamask")
    } 
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function above collects the user's address and signer which allows us to request a transaction to the network. In this case I will demonstrate how to send Matic on Polygon.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const requestPolygonTransaction = async (signer, address, provider) =&amp;gt; {
    // check validity of addresses
    if (
      !web3.utils.isAddress(address) || !web3.utils.isAddress(process.env.NEXT_PUBLIC_OWNER_WALLET)
    ) {
      console.log('ERROR invalid wallet addresses provided')
      return
    }

    const transactionParameters = {
      from: address, // sender wallet address
      to: process.env.NEXT_PUBLIC_OWNER_WALLET,  // receiver address
      data: '0x',
      value: ethers.utils.parseEther(polygonAmount),
      gasLimit: ethers.utils.hexlify(10000),
      gasPrice: ethers.utils.hexlify(parseInt(await provider.getGasPrice())),
    }

    await signer
      .sendTransaction(transactionParameters)
      .then((transaction) =&amp;gt; {
        isModalVisible = false
        Modal.success({
          title: 'Transaction success!',
      })
      .catch((e) =&amp;gt; {
        console.log('failed!')
        Modal.error({
          title: 'Oops transaction failed!',
          content: 'please double check the amount and try again',
        })

        return
      })
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To help with things I'm using a Polygon node endpoint provided by &lt;a href="https://www.alchemy.com/"&gt;Alchemy&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Putting things all together this is what my final code looks like to send matic on polygon using ethers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Modal, Input, Tooltip } from 'antd'
import { ethers } from 'ethers'
import Web3 from 'web3'
import Web3Modal from 'web3modal'
import utilStyles from '../styles/utils.module.css'
import 'antd/dist/antd.css'

const web3 = new Web3(process.env.NEXT_PUBLIC_ALCHEMY_ENDPOINT)

export default function CryptoCheckout({
  isModalVisible,
  handleOk,
  handleCancel,
  polygonAmount,
  updateAmount,
}) {
  const connectToMetamask = async () =&amp;gt; {
    const web3Modal = new Web3Modal()
    const connection = await web3Modal.connect()
    const provider = new ethers.providers.Web3Provider(connection)
    const signer = provider.getSigner()
    const address = await signer.getAddress()
    if (address &amp;amp;&amp;amp; signer &amp;amp;&amp;amp; provider) {
      requestPolygonTransaction(signer, address, provider)
    } else {
      console.log("ERROR couldn't connect to metamask")
    }
  }

  const requestPolygonTransaction = async (signer, address, provider) =&amp;gt; {
    // check validity of addresses
    if (
      !web3.utils.isAddress(address) ||
   !web3.utils.isAddress(process.env.NEXT_PUBLIC_OWNER_WALLET)
    ) {
      console.log('ERROR invalid wallet addresses provided')
      return
    }

    const transactionParameters = {
      from: address,
      to: process.env.NEXT_PUBLIC_OWNER_WALLET, 
      data: '0x',
      value: ethers.utils.parseEther(polygonAmount),
      gasLimit: ethers.utils.hexlify(10000),
      gasPrice: ethers.utils.hexlify(parseInt(await provider.getGasPrice())),
    }

    await signer
      .sendTransaction(transactionParameters)
      .then((transaction) =&amp;gt; {
        isModalVisible = false
        Modal.success({
          title: 'Tx Success!'
      })
      .catch((e) =&amp;gt; {
        console.log('failed!')
        Modal.error({
          title: 'Oops transaction failed!',
          content: 'please double check the amount and try again',
        })

        return
      })
  }

  return (
    &amp;lt;&amp;gt;
      &amp;lt;Modal
        title="Crypto Checkout"
        visible={isModalVisible}
        onOk={handleOk}
        onCancel={handleCancel}
        footer={[
          &amp;lt;button
            key="submit"
            className={`${utilStyles.primaryButton}`}
            onClick={connectToMetamask}
          &amp;gt;
            Submit
          &amp;lt;/button&amp;gt;,
        ]}
      &amp;gt;
        &amp;lt;p&amp;gt;Enter amount in polygon (MATIC) you'd like to send&amp;lt;/p&amp;gt;

        &amp;lt;Input
          prefix=""
          className={`${utilStyles.input}`}
          value={polygonAmount}
          onChange={updateAmount}
          placeholder="50"
          suffix="matic"
        /&amp;gt;
      &amp;lt;/Modal&amp;gt;
    &amp;lt;/&amp;gt;
  )
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it! You can also use the same method to send ether and any other Ethereum based token.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Update Google Cloud Run Instance using an API Axios Request</title>
      <dc:creator>Cormac</dc:creator>
      <pubDate>Thu, 12 May 2022 01:41:51 +0000</pubDate>
      <link>https://dev.to/cormacncheese/how-to-update-google-cloud-run-instance-using-an-api-axios-request-25hc</link>
      <guid>https://dev.to/cormacncheese/how-to-update-google-cloud-run-instance-using-an-api-axios-request-25hc</guid>
      <description>&lt;p&gt;This tutorial is explains how to update an existing google cloud run instance using a google cloud build docker image.&lt;/p&gt;

&lt;p&gt;First to push your docker image to Google Cloud you can run the following from your local codebase:&lt;br&gt;
&lt;code&gt;gcloud builds submit --timeout=2000s --machine-type=e2-highcpu-32 --tag gcr.io/PROJECT-NAME/IMAGE-NAME .&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will build your docker project and store it as an image in GCP container registry.&lt;/p&gt;

&lt;p&gt;Then to deploy the image as a Google Cloud instance you can run this command:&lt;br&gt;
&lt;code&gt;gcloud run deploy INSTANCE-NAME --image gcr.io/PROJECT-NAME/IMAGE-NAME --region us-east1 --platform managed --allow-unauthenticated --quiet&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Cool! Now our docker project is running in Cloud Run.&lt;/p&gt;

&lt;p&gt;In my case I use have different code bases for different website themes and build them using docker. So I used the first command to submit all my themes to Google Cloud, but I needed a programmatic way to overwrite my cloud run instance with a new docker image when switching between themes from my frontend app.&lt;/p&gt;

&lt;p&gt;Usually you could run the &lt;code&gt;gcloud run deploy&lt;/code&gt; CLI command but I needed to convert the CLI command to an axios API request I add to a cloud function in my backend.&lt;/p&gt;

&lt;p&gt;Here's I did it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;try {
async function updateTheme() {
  let token: any
  const jwtClient = new google.auth.JWT(firebaseClientEmail, "", firebaseKey, [
    'https://www.googleapis.com/auth/cloud-platform',
  ])

  await jwtClient.authorize(async function (err: any, _token: any) {
    if (err) {
      console.log("JWT ERROR: ", err)
      return err
    } else {
      token = _token.access_token.split('.')
      token = token[0] + '.' + token[1] + '.' + token[2]

      const deploySteps = [
        {
          name: 'gcr.io/cloud-builders/gcloud',
          args: [
            'run',
            'deploy',
            `${name}`,
            '--image',
            `gcr.io/${googleCloudProject}/theme-${theme}`,
            '--region',
            'us-east1',
            '--allow-unauthenticated',
            '--platform',
            'managed',
            '--quiet',
          ],
        },
      ]

      const deployRevisions = async () =&amp;gt; {
        await axios({
          method: "post",
          url: `https://cloudbuild.googleapis.com/v1/projects/${googleCloudProject}/builds`,
          headers: {
            Authorization: `Bearer ${token}`,
          },
          data: {
            steps: deploySteps,
            timeout: "1200s",
          },
        })
          .catch(function (error: any) {
            console.log("ERROR UPDATING THEME: ", error)
            return
          })
          .then(function (response: any) {
            console.log("SUCCESSFULLY DEPLOYED THEME UPDATE")
          })
      }

      if (token) {
        deployRevisions()
      } else {
        console.log("MISSING TOKEN")
      }
    }
  })
}

await updateTheme()

} catch (e) {
    console.log("tried updating theme but something went wrong")
    return
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above chunk of code utilizes the Cloud Build API to overwrite a cloud run instance with a docker image in Google Cloud. It fetches the Google Cloud authentication code to use in the request as well.&lt;/p&gt;

&lt;p&gt;Place it in a function and simple pass in the image name when you wish to update your cloud run instance&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>googlecloud</category>
      <category>webdev</category>
      <category>docker</category>
    </item>
    <item>
      <title>Deploying an Expo Web React Native App to Google Cloud</title>
      <dc:creator>Cormac</dc:creator>
      <pubDate>Thu, 14 Apr 2022 23:35:35 +0000</pubDate>
      <link>https://dev.to/cormacncheese/deploying-an-expo-web-react-native-app-to-google-cloud-4006</link>
      <guid>https://dev.to/cormacncheese/deploying-an-expo-web-react-native-app-to-google-cloud-4006</guid>
      <description>&lt;p&gt;Building mobile apps has never been easier thanks to Expo. According to their website, Expo is an open-source platform for making universal native apps for Android, iOS, and the web with JavaScript and React.&lt;/p&gt;

&lt;p&gt;Paired with Google Cloud Run, highly scalable containerized a fully managed serverless platform, Expo web apps can be extremely quick to make and ship.&lt;/p&gt;

&lt;p&gt;Here’s how to build and deploy your React Native Expo web app to Google Cloud Run:&lt;/p&gt;

&lt;h2&gt;
  
  
  0) Setup Expo
&lt;/h2&gt;

&lt;p&gt;I’m assuming you already have an Expo app setup and running locally (their docs are super easy to follow)&lt;/p&gt;

&lt;h2&gt;
  
  
  1) Add a Dockerfile to the root of your application
&lt;/h2&gt;

&lt;p&gt;You can copy and paste this one into your project:&lt;/p&gt;

&lt;p&gt;`# build environment&lt;br&gt;
FROM node:14-alpine as react-build&lt;/p&gt;

&lt;h1&gt;
  
  
  install global packages
&lt;/h1&gt;

&lt;p&gt;ENV NPM_CONFIG_PREFIX=/home/node/.npm-global&lt;br&gt;
ENV PATH /home/node/.npm-global/bin:$PATH&lt;br&gt;
RUN npm i --unsafe-perm -g npm@latest expo-cli@latest&lt;br&gt;
WORKDIR /app&lt;br&gt;
ADD . ./&lt;br&gt;
RUN yarn&lt;br&gt;
RUN npx expo-optimize&lt;/p&gt;

&lt;h1&gt;
  
  
  used for ENV
&lt;/h1&gt;

&lt;p&gt;RUN expo build:web --release-channel prod&lt;/p&gt;

&lt;h1&gt;
  
  
  server environment
&lt;/h1&gt;

&lt;p&gt;FROM nginx:alpine&lt;br&gt;
ADD nginx.conf /etc/nginx/conf.d/configfile.template&lt;br&gt;
COPY --from=react-build /app/web-build /usr/share/nginx/html&lt;br&gt;
ENV PORT 8080&lt;br&gt;
ENV HOST 0.0.0.0&lt;br&gt;
EXPOSE 8080&lt;br&gt;
CMD sh -c "envsubst '\$PORT' &amp;lt; /etc/nginx/conf.d/configfile.template &amp;gt; /etc/nginx/conf.d/default.conf &amp;amp;&amp;amp; nginx -g 'daemon off;'"`&lt;/p&gt;

&lt;p&gt;The key elements here which are super important is making sure to expo-cli as well as including the RUN npx expo-optimize and RUN expo build:web — release-channel prod commands.&lt;/p&gt;

&lt;p&gt;These include all the necessary Expo packages and scripts.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Setup Google Cloud
&lt;/h2&gt;

&lt;p&gt;You’ll need to make sure you’ve enabled Cloud Build, Cloud Run and Container Registry in your project.&lt;/p&gt;

&lt;p&gt;You’ll also need to sign into Gcloud from the command line:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;gcloud auth login&lt;br&gt;
gcloud config set project YOUR_PROJECT_ID&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Build using Docker&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;gcloud builds submit --timeout=2000s --machine-type=N1_HIGHCPU_8 --tag gcr.io/YOUR_PROJECT_ID/frontend&lt;/p&gt;

&lt;p&gt;You can remove the machine-type=N1_HIGHCPU_8 tag if you want to use the starter level server. Make sure to add your project ID.&lt;/p&gt;

&lt;p&gt;The cli will prompt you to enter a project name&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Submit build to Google Cloud Run
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;gcloud run deploy YOUR_PROJECT_NAME —image gcr.io/mortar-329801/frontend --region us-west2 --platform managed&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Feel free to change the region.&lt;/p&gt;

&lt;p&gt;And your app is live!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>tutorial</category>
      <category>devops</category>
      <category>reactnative</category>
    </item>
    <item>
      <title>How to Access ENV Variables in Google Cloud Run using Next.js</title>
      <dc:creator>Cormac</dc:creator>
      <pubDate>Thu, 14 Apr 2022 23:31:48 +0000</pubDate>
      <link>https://dev.to/cormacncheese/how-to-access-env-variables-in-google-cloud-run-using-nextjs-2o8g</link>
      <guid>https://dev.to/cormacncheese/how-to-access-env-variables-in-google-cloud-run-using-nextjs-2o8g</guid>
      <description>&lt;p&gt;If you’re building a web application, Google Cloud Run is a great option for you to deploy microservices to the cloud. It’s built on top of Kubernetes and allows you to scale backend and monorepos with ease.&lt;/p&gt;

&lt;p&gt;However, when our team at &lt;a href="https://ownchain.it/"&gt;Ownchain&lt;/a&gt; was working to deploy our users’ based on a Docker image sitting in Google Cloud Build and Container Registry, our client-side code was unable to access our environment variables set in Cloud Run–they were showing up as undefined.&lt;/p&gt;

&lt;p&gt;Here’s how we were able to deploy our Next.js monorepo application to Google Cloud using Docker and dynamic ENV variables:&lt;/p&gt;

&lt;p&gt;I’m assuming you have already setup lerna and can run you’re application locally.&lt;/p&gt;

&lt;h2&gt;
  
  
  Initial Setup
&lt;/h2&gt;

&lt;p&gt;This is the key to exposing your ENV variables to the client once you deploy your application to Cloud Run.&lt;/p&gt;

&lt;p&gt;We ended up using @beam-australia/react-env to fetch ENV variables from the server and expose them to the client. &lt;/p&gt;

&lt;p&gt;You can follow the NEXT.js example in their repo, or they also have instructions if you used Create React App.&lt;br&gt;
Here’s an example of how it works:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;// package.json&lt;br&gt;
{&lt;br&gt;
  "name": "web",&lt;br&gt;
  "version": "0.1.0",&lt;br&gt;
  "dependencies": {&lt;br&gt;
    "@beam-australia/react-env": "^3.1.1",&lt;br&gt;
    "next": "^11.0.1",&lt;br&gt;
    "next-compose-plugins": "^2.2.1",&lt;br&gt;
    "next-with-less": "^1.0.0",&lt;br&gt;
    "react": "17.0.2",&lt;br&gt;
    "react-dom": "17.0.2",&lt;br&gt;
    "react-env": "^0.0.0",&lt;br&gt;
    "react-router-dom": "^5.2.0",&lt;br&gt;
  },&lt;br&gt;
  "scripts": {&lt;br&gt;
    "start": "react-env --path ../../../.env -- next dev",&lt;br&gt;
    "build": "next build",&lt;br&gt;
    "export": "next export",&lt;br&gt;
    "start:prod": "react-env --path ../../../.env -- next start",&lt;br&gt;
    "test": "jest",&lt;br&gt;
  },&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Using the react-env package we can set a custom path for our .env file within our monorepo application.&lt;/p&gt;

&lt;p&gt;`// app.tsx&lt;br&gt;
import React, { useEffect } from 'react';&lt;br&gt;
import Head from 'next/head';&lt;br&gt;
import env from "@beam-australia/react-env";&lt;/p&gt;

&lt;p&gt;function App() {&lt;br&gt;
 useEffect(() =&amp;gt; {&lt;br&gt;
   console.log("Firebase User: ",  env("FIREBASE_USER_ID"))&lt;br&gt;
  }, [])&lt;/p&gt;

&lt;p&gt;return (&lt;br&gt;
    &amp;lt;&amp;gt;&lt;br&gt;
      &lt;/p&gt;
&lt;br&gt;
        &lt;br&gt;
        Ownchain&lt;br&gt;
        &lt;br&gt;
      &lt;br&gt;
    &amp;lt;/&amp;gt;&lt;br&gt;
  );&lt;br&gt;
}`

&lt;p&gt;By adding the script t our &lt;/p&gt; component we can read in our ENV variables using env("FIREBASE_USER_ID") format.
&lt;h2&gt;
  
  
  Some Devops Stuff
&lt;/h2&gt;

&lt;p&gt;Once that’s all setup, you should have your Dockerfile in the root directory ready to go. Our’s looked something like this:&lt;/p&gt;

&lt;p&gt;`# Stage 1: Compile and Build the app&lt;/p&gt;

&lt;h1&gt;
  
  
  Node version
&lt;/h1&gt;

&lt;p&gt;FROM node:14.17.3-alpine as build&lt;/p&gt;

&lt;h1&gt;
  
  
  Check &lt;a href="https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine"&gt;https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine&lt;/a&gt; to understand why libc6-compat might be needed.
&lt;/h1&gt;

&lt;p&gt;RUN apk add --no-cache libc6-compat git&lt;/p&gt;

&lt;h1&gt;
  
  
  Set the working directory
&lt;/h1&gt;

&lt;p&gt;WORKDIR /app&lt;/p&gt;

&lt;h1&gt;
  
  
  Add the source code to app
&lt;/h1&gt;

&lt;p&gt;COPY ./js /app&lt;/p&gt;

&lt;h1&gt;
  
  
  Install all the dependencies
&lt;/h1&gt;

&lt;p&gt;RUN yarn install&lt;br&gt;
RUN yarn bootstrap&lt;/p&gt;

&lt;h1&gt;
  
  
  Generate the build of the application
&lt;/h1&gt;

&lt;p&gt;RUN yarn build&lt;/p&gt;

&lt;h1&gt;
  
  
  Stage 2: Serve app with nginx server
&lt;/h1&gt;

&lt;h1&gt;
  
  
  Production image, copy all the files and run next
&lt;/h1&gt;

&lt;p&gt;FROM node:14.17.3-alpine AS runner&lt;br&gt;
WORKDIR /app&lt;br&gt;
ENV NODE_ENV production&lt;br&gt;
RUN addgroup -g 1001 -S nodejs&lt;br&gt;
RUN adduser -S nextjs -u 1001&lt;/p&gt;

&lt;h1&gt;
  
  
  Copy the build output to replace the default nginx contents.
&lt;/h1&gt;

&lt;p&gt;COPY --from=build /app/packages/web/next.config.js ./&lt;br&gt;
COPY --from=build /app/packages/web/public ./public&lt;br&gt;
COPY --from=build --chown=nextjs:nodejs /app/packages/web/.next ./.next&lt;br&gt;
COPY --from=build /app/node_modules ./node_modules&lt;br&gt;
COPY --from=build /app/packages/web/package.json ./package.json&lt;br&gt;
USER root&lt;br&gt;
EXPOSE 3000&lt;br&gt;
CMD ["yarn", "start:prod"]`&lt;/p&gt;

&lt;p&gt;**Make sure to add your USER as root otherwise @beam-australia/react-env won’t have enough access to your environment variables.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sync Github with CloudBuild and set Cloud Run Automated Deployments
&lt;/h2&gt;

&lt;p&gt;This is pretty easy to setup, Google has some great documentation for this: &lt;a href="https://cloud.google.com/build/docs/automating-builds/build-repos-from-github"&gt;https://cloud.google.com/build/docs/automating-builds/build-repos-from-github&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In addition, we can also utilize Cloud Functions to setup continuous delivery to Cloud Run with each new Cloud Build using Pub/Sub. Follow this article for specific instructions: &lt;a href="https://medium.com/google-cloud/continuous-deployment-to-cloud-run-services-based-on-a-new-container-image-bccd776b7357"&gt;https://medium.com/google-cloud/continuous-deployment-to-cloud-run-services-based-on-a-new-container-image-bccd776b7357&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Showing it off
&lt;/h2&gt;

&lt;p&gt;Now we can add ENV variables directly to Cloud Run:&lt;/p&gt;

&lt;p&gt;Or you can add them as tags with API or CLI requests like so (see bottom):&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"run",&lt;br&gt;
"deploy",&lt;br&gt;
&lt;/code&gt;${serviceName}&lt;code&gt;,&lt;br&gt;
"--image",&lt;br&gt;
"gcr.io/GOOGLE_CLOUD_PROJECT/store",&lt;br&gt;
"--region",&lt;br&gt;
"us-west2",&lt;br&gt;
"--allow-unauthenticated",&lt;br&gt;
"--platform",&lt;br&gt;
"managed",&lt;br&gt;
"--update-env-vars",&lt;br&gt;
&lt;/code&gt;REACT_APP_FIREBASE_USER_ID=${userId},REACT_APP_STORE_LOGO=${logoUrl}``&lt;/p&gt;

&lt;p&gt;Now when you visit your Cloud Run url your client will be able to access your env variables. 🥳&lt;/p&gt;

</description>
      <category>cloud</category>
      <category>docker</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to Deploy Your Shopify React App to Heroku</title>
      <dc:creator>Cormac</dc:creator>
      <pubDate>Thu, 14 Apr 2022 23:24:32 +0000</pubDate>
      <link>https://dev.to/cormacncheese/how-to-deploy-your-shopify-react-app-to-heroku-2hak</link>
      <guid>https://dev.to/cormacncheese/how-to-deploy-your-shopify-react-app-to-heroku-2hak</guid>
      <description>&lt;p&gt;I followed the &lt;a href="https://shopify.dev/apps/getting-started"&gt;Build a Shopify App with Node and React&lt;/a&gt; to start my first Shopify app. The server sets you up using a local ngrok server which was pretty impractical since I travel a bit.&lt;/p&gt;

&lt;p&gt;The steps are as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create new app on Heroku&lt;/li&gt;
&lt;li&gt;Connect app with your Github repo/branch (it may take a minute or two to load)&lt;/li&gt;
&lt;li&gt;Place your SHOPIFY_API_KEY and SHOPIFY_API_SECRET_KEY in your Heroku app’s Config Vars located in Settings.&lt;/li&gt;
&lt;li&gt;Update your Shopify App Urls with your live Heroku app link (&lt;a href="https://example-app.herokuapp.com/"&gt;https://example-app.herokuapp.com/&lt;/a&gt;) and (&lt;a href="https://example-app.herokuapp.com/auth/callback"&gt;https://example-app.herokuapp.com/auth/callback&lt;/a&gt;)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That’s it. Your app should be live and ready to scale!&lt;/p&gt;

</description>
      <category>shopify</category>
      <category>heroku</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How to Run Firebase Functions Emulator on your iPhone using Expo</title>
      <dc:creator>Cormac</dc:creator>
      <pubDate>Thu, 14 Apr 2022 23:21:17 +0000</pubDate>
      <link>https://dev.to/cormacncheese/how-to-run-firebase-functions-emulator-on-your-iphone-using-expo-5b82</link>
      <guid>https://dev.to/cormacncheese/how-to-run-firebase-functions-emulator-on-your-iphone-using-expo-5b82</guid>
      <description>&lt;p&gt;Using Expo makes developing React Native apps incredibly easy and it works great with many tools including firebase.&lt;/p&gt;

&lt;p&gt;By following these steps you can setup your React Native Expo app with firebase functions and run them locally.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up Expo and React Native
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;yarn global add expo-cli&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
then..&lt;/p&gt;

&lt;p&gt;&lt;code&gt;expo init AwesomeProject &lt;br&gt;
cd AwesomeProject&lt;br&gt;
yarn start&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Boom done.&lt;/p&gt;

&lt;h2&gt;
  
  
  Connect with Firebase Functions
&lt;/h2&gt;

&lt;p&gt;First you’re going to want to go to console.firebase.com, create a project and add a web app. Make sure to activate all the services you’re interested in using including Firebase Functions by clicking through the left menu bar.&lt;/p&gt;

&lt;p&gt;Then switch back to your code editor and install firebase:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;expo install firebase&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Then you need to create a firebase.js file in the root of your directory and add your config details that you can find in the Firebase console. Mine looks like the following:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import firebase from 'firebase/app'&lt;br&gt;
import 'firebase/firestore'&lt;br&gt;
import 'firebase/functions'&lt;br&gt;
import 'firebase/storage'&lt;br&gt;
import 'firebase/auth';&lt;br&gt;
// Initialize Firebase&lt;br&gt;
const firebaseConfig = {&lt;br&gt;
  apiKey: PLACE_YOUR_CONFIG_HERE,&lt;br&gt;
  authDomain: PLACE_YOUR_CONFIG_HERE,&lt;br&gt;
  databaseURL: PLACE_YOUR_CONFIG_HERE,&lt;br&gt;
  projectId: PLACE_YOUR_CONFIG_HERE,&lt;br&gt;
  storageBucket: PLACE_YOUR_CONFIG_HERE,&lt;br&gt;
  messagingSenderId: PLACE_YOUR_CONFIG_HERE,&lt;br&gt;
  appId: PLACE_YOUR_CONFIG_HERE,&lt;br&gt;
  measurementId: PLACE_YOUR_CONFIG_HERE&lt;br&gt;
};&lt;br&gt;
if (!firebase.apps.length) {&lt;br&gt;
   firebase.initializeApp(firebaseConfig) &lt;br&gt;
} else {&lt;br&gt;
   firebase.app(); // if already initialized, use that one&lt;br&gt;
}&lt;br&gt;
export const firestoreDatabase = firebase.firestore()&lt;br&gt;
export const firebaseStorage = firebase.storage()&lt;br&gt;
export const firebaseFunctions = firebase.functions()&lt;br&gt;
export const firebaseAuth = firebase.auth()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Cool, next enter firebase init into the command line and select functions and press enter. Firebase will setup the folder structure and add an index.js or index.txs file for you to get started. Edit these as you please.&lt;/p&gt;

&lt;h2&gt;
  
  
  Running Firebase Functions Locally
&lt;/h2&gt;

&lt;p&gt;If you want to test out your react native app in the Expo interface on your mobile device you’re going to need your IP address, specifically your IP4v address which you can find here: &lt;a href="https://whatismyipaddress.com/"&gt;https://whatismyipaddress.com/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Good, now that you’ve got your IP, switch back to your firebase.js file and let’s add another line.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;firebase.functions().useEmulator("PLACE_YOUR_IP_HERE:5001");&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Then we need to edit our firebase.json file and add a new “host” line to our emulator settings like so:&lt;br&gt;
&lt;code&gt;&lt;br&gt;
"emulators": {&lt;br&gt;
    "functions": {&lt;br&gt;
      "port": 5001,&lt;br&gt;
      "host": "0.0.0.0"&lt;br&gt;
    },&lt;br&gt;
    "ui": {&lt;br&gt;
      "enabled": true&lt;br&gt;
    }&lt;br&gt;
  },&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Sweet.&lt;/p&gt;

&lt;p&gt;If you added configs to your firebase functions you’ll need to run the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;firebase functions:config:get &amp;gt; .runtimeconfig.json&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
If you’re using Typescript functions make sure to run this as well:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cd functions&lt;br&gt;
npx tsc --watch&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Now We’re Ready
&lt;/h2&gt;

&lt;p&gt;Now that’s setup we are ready to run:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;firebase emulators:start — only functions&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
If all went well your firebase functions should be responding when you expo start and test your app on your mobile device.&lt;/p&gt;

</description>
      <category>firebase</category>
      <category>reactnative</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Local and Production ENV Variables using Expo React Native</title>
      <dc:creator>Cormac</dc:creator>
      <pubDate>Thu, 14 Apr 2022 23:17:18 +0000</pubDate>
      <link>https://dev.to/cormacncheese/local-and-production-env-variables-using-expo-react-native-5d4f</link>
      <guid>https://dev.to/cormacncheese/local-and-production-env-variables-using-expo-react-native-5d4f</guid>
      <description>&lt;p&gt;Expo recently came out with a new feature which makes managing ENVs a lot easier using what they call a dynamic app config file.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Here’s you to setup env variables for different environments in Expo:&lt;br&gt;
*&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create and app.config.js file at the root of your repo&lt;/li&gt;
&lt;li&gt;Populate the file, it should look something like this:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;import 'dotenv/config';&lt;/p&gt;

&lt;p&gt;&lt;code&gt;export default {&lt;br&gt;
     name: 'APP_NAME',&lt;br&gt;
     version: '1.0.0',&lt;br&gt;
     extra: {&lt;br&gt;
         environment: 'dev'&lt;br&gt;
     },&lt;br&gt;
};&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Call variable. Now when we run our application, we can access the environment variable by doing the following:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;import Constants from 'expo-constants';&lt;br&gt;
export default function App(props) {&lt;br&gt;
     console.log("props.environment: ", props.environment)&lt;br&gt;
}&lt;br&gt;
App.defaultProps = {&lt;br&gt;
     environment: Constants.manifest.extra.environment,&lt;br&gt;
};&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Setup different variables for production and local development. To do this, we’ll need to change out deploy script to manually add a variable describing the environment.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I place mine in a Dockerfile which Google Cloud uses to build my application:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;RUN ENVIRONMENT=prod expo build:web&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
But you you add the ENVIRONMENT=prod to wherever you are building your app.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Update the app.config.js to make variables dynamic based on the environment.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;import 'dotenv/config';&lt;br&gt;
if (process.env.ENVIRONMENT === 'prod') {&lt;br&gt;
    export default {&lt;br&gt;
    name: 'APP_NAME',&lt;br&gt;
         version: '1.0.0',&lt;br&gt;
         extra: {&lt;br&gt;
              environment: 'prod'&lt;br&gt;
         },&lt;br&gt;
     };&lt;br&gt;
} else {&lt;br&gt;
      export default {&lt;br&gt;
         name: 'APP_NAME',&lt;br&gt;
         version: '1.0.0',&lt;br&gt;
         extra: {&lt;br&gt;
               environment: 'dev'&lt;br&gt;
          },&lt;br&gt;
     };&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here we check the ENVIRONMENT variable and then we can update the extra variables based on where we are using our app. When we deploy our app will use variables defined in the top section.&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>javascript</category>
      <category>programming</category>
      <category>react</category>
    </item>
    <item>
      <title>How to make an API Query the Blockchain</title>
      <dc:creator>Cormac</dc:creator>
      <pubDate>Thu, 14 Apr 2022 17:03:34 +0000</pubDate>
      <link>https://dev.to/cormacncheese/how-to-make-an-api-query-the-blockchain-5fni</link>
      <guid>https://dev.to/cormacncheese/how-to-make-an-api-query-the-blockchain-5fni</guid>
      <description>&lt;p&gt;Blockchain makes data public to anyone however it can be a little tricky to access.&lt;/p&gt;

&lt;p&gt;In this blog I’ll break down how to make API requests to blockchains, using Avalanche as an example.&lt;/p&gt;

&lt;p&gt;Much of Avalanche’s API functionality requires you to have access to each Node’s permissions or to run your own node which currently has a startup staking fee of 2,000 AVAX or $126,000.&lt;/p&gt;

&lt;p&gt;For developers who wish to access Avalanches on-chain data without staking their own node, the Avalanche team provides a public endpoint to make api requests.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.avax.network/build/tools/public-api/"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For this demonstration we will be request the latest block from Avalanche’s C-Chain.&lt;/p&gt;

&lt;p&gt;Because the C-Chain is an instance of the Ethereum Virtual Machine powered, you can request much of the same information you could using GETH in Ethereum:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ethereum/execution-apis/tree/main/src/eth"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Let’s Get Started
&lt;/h2&gt;

&lt;p&gt;To make things easy, we’ll first request the latest block curl. Using the first link above, we see we can request information from the C-chain using &lt;br&gt;
&lt;a href="https://api.avax.network/ext/bc/C/rpc"&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;By browsing through the eth execution-apis in the second link we can use &lt;code&gt;eth_getBlockByNumber&lt;/code&gt; to get the latest block data.&lt;/p&gt;

&lt;p&gt;Putting it all together we get the following curl request:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;curl -X POST --data '{&lt;br&gt;
     "jsonrpc":"2.0",&lt;br&gt;
     "id"     :1,&lt;br&gt;
     "method":"eth_getBlockByNumber",&lt;br&gt;
     "params":["latest", false]&lt;br&gt;
}' -H 'content-type:application/json;' https://api.avax.network/ext/bc/C/rpc&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you open terminal, paste and enter this command you should get a response looking similar to this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jAYu6F_q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rt8b2p316zv0b4eyjksi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jAYu6F_q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rt8b2p316zv0b4eyjksi.png" alt="Image description" width="880" height="173"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Congratulations! You just made a request to the Avalanche blockchain.&lt;/p&gt;

&lt;h2&gt;
  
  
  Avalanche Request using HTTP Postman
&lt;/h2&gt;

&lt;p&gt;If you prefer http requests, we can make the same request be using postman:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--So9D5aPK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ztwgfcu4r2bdpb8ii3y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--So9D5aPK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ztwgfcu4r2bdpb8ii3y.png" alt="Image description" width="880" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Paste in link and the body into Postman like in the screenshot above, then press Send.&lt;/p&gt;

&lt;p&gt;You’ll get a response looking like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--g8qs4-Fn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zn4dzsef7iuch31lfyoi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--g8qs4-Fn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zn4dzsef7iuch31lfyoi.png" alt="Image description" width="880" height="290"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Just like before we can see the latest block’s gas fee, height, transaction hashes and more.&lt;/p&gt;

&lt;h2&gt;
  
  
  We could also use Axios
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;await axios.post(postUrl, {&lt;br&gt;
     "jsonrpc": "2.0",&lt;br&gt;
     "id": 1,&lt;br&gt;
     "method": "eth_getBlockByNumber",&lt;br&gt;
     "params": ["latest", false]&lt;br&gt;
})&lt;br&gt;
.then((res: any) =&amp;gt; {&lt;br&gt;
     console.log("AVAX BLOCK DATA: ", res.data.result)&lt;br&gt;
})&lt;br&gt;
.catch((err: any) =&amp;gt; {&lt;br&gt;
     console.log("err: ", err.response)&lt;br&gt;
     return err&lt;br&gt;
})&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once you get the hang of it, requesting Avalanche and Ethereum chains is pretty straightforward and by using public APIs we can save a lot of resources.&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>ethereum</category>
      <category>api</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
