SyntaxError: Unexpected token '?' in upgrading smart contract using #openzeppelin/hardhat-upgrades - blockchain

I am trying to deploy an upgradable smart contract on polygon Mumbai tesnet. I am getting this error
smart-contract/node_modules/#openzeppelin/hardhat-upgrades/dist/index.js:108
compiler.settings ?? (compiler.settings = {});
^
SyntaxError: Unexpected token '?'
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Object.require.extensions.<computed> [as .js] (/Users/jagdish/workspace/speedrun-simple-nft-example/smart-contract/node_modules/ts-node/src/index.ts:1587:43)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/Users/jagdish/workspace/speedrun-simple-nft-example/smart-contract/hardhat.config.ts:4:1)
at Module._compile (internal/modules/cjs/loader.js:999:30)
while trying to run the deploy script.
here are my configs and deploy scripts:
hardhart.config.ts
import { task } from "hardhat/config";
// import "#nomiclabs/hardhat-waffle";
import 'hardhat-watcher';
import '#openzeppelin/hardhat-upgrades';
import '#nomiclabs/hardhat-ethers';
import dotenv from "dotenv"
dotenv.config()
// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
const accounts = await hre.ethers.getSigners();
for (const account of accounts) {
console.log(account.address);
}
});
// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more
/**
* #type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
solidity: "0.8.4",
watcher: {
compilation: {
tasks: ['compile'],
},
node: {
tasks: ['node'],
},
},
networks: {
matic: {
url: "https://polygon-rpc.com/",
accounts: [process.env.ACCOUNT_PRIVATE_KEY]
},
matic_mumbai: {
url: "https://rpc-mumbai.maticvigil.com",
accounts: [process.env.ACCOUNT_PRIVATE_KEY]
}
}
};
deploy.ts
import { ethers, upgrades } from "hardhat";
async function main() {
const contract = await ethers.getContractFactory("YourCollectible");
console.log("Deploying Contract ...");
const c = await upgrades.deployProxy(contract, { constructorArgs: ["Your Collectables", "YCB"] })
// const c = await contract.deploy("Your Collectable", "YCB");
await c.deployed();
console.log("Contract deployed to:", c.address);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
package.json
{
"name": "smart-contract",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"run": "hardhat compile",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"#nomiclabs/hardhat-ethers": "^2.0.6",
"#nomiclabs/hardhat-waffle": "^2.0.3",
"#openzeppelin/hardhat-upgrades": "^1.20.0",
"#typechain/hardhat": "^6.1.2",
"chai": "^4.3.6",
"ethereum-waffle": "^3.4.4",
"ethers": "^5.6.9",
"hardhat": "^2.9.9",
"hardhat-watcher": "^2.3.0",
"ts-node": "^10.8.1",
"typescript": "^4.7.4"
},
"dependencies": {
"#openzeppelin/contracts": "^4.7.0",
"dotenv": "^16.0.1"
}
}
I am not sure whether it is the node version issue in my local or do I have to downgrade the #openzeppelin/hardhat-upgrades version (I have tried that).
Node version: v12.22.10
Can anyone help on this

I had the same problem with node 12. Problem solved after updating to node 16 and running yarn again.

Related

NextJS Amplify auth cognito not authenticated on server aws

I'm using cognito for authentication of my app.
In local enviroment everthing it's ok whether launch yarn dev or yarn build and yarn start.
In the amplify server deploy the SSR authentication not working: return always "not authenticated".
This is mine package.json:
{
"name": "xxxxxxxxxxxx",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start -p ${PORT:=3000}",
"lint": "next lint"
},
"dependencies": {
"#fortawesome/fontawesome-svg-core": "^6.1.2",
"#fortawesome/free-regular-svg-icons": "^6.1.2",
"#fortawesome/free-solid-svg-icons": "^6.1.2",
"#fortawesome/react-fontawesome": "^0.1.18",
"#improbable-eng/grpc-web": "^0.14.0",
"#improbable-eng/grpc-web-node-http-transport": "^0.14.0",
"#nivo/bar": "^0.74.0",
"#nivo/core": "^0.74.0",
"#nivo/geo": "^0.74.0",
"#nivo/pie": "^0.74.0",
"#nivo/scatterplot": "^0.74.0",
"#nivo/treemap": "^0.74.0",
"apexcharts": "^3.35.3",
"aws-amplify": "^4.3.34",
"axios": "^0.24.0",
"bootstrap": "^5.2.0",
"cors": "^2.8.5",
"emotion": "^11.0.0",
"eslint-config-next": "^12.2.4",
"google-protobuf": "^3.17.2",
"human-readable-numbers": "^0.9.5",
"jspdf": "^2.5.0",
"next": "12.0.0",
"next-i18next": "^12.0.0",
"rc-slider": "10.0.1",
"react": "^17.0.2",
"react-apexcharts": "^1.4.0",
"react-bootstrap": "^2.4.0",
"react-dom": "^17.0.2",
"react-read-more-read-less": "^1.0.7",
"react-sparklines": "^1.7.0",
"react-toastify": "^9.0.8",
"react-tradingview-widget": "^1.3.2",
"sass": "1.32.13",
"sharp": "^0.29.3",
"swr": "^0.5.6",
"xmlhttprequest": "^1.8.0"
},
"devDependencies": {
"eslint": "7.32.0"
}
}
This is _app.js (pages/_app.js):
import getConfig from "next/config";
import { appWithTranslation } from "next-i18next";
import "../public/app.scss";
import { Amplify } from "aws-amplify";
import awsExports from "../src/aws-exports";
import React from "react";
import AuthContext from "../components/context/AuthContext";
import { Header } from "../components/dashboard/Header";
import { Footer } from "../components/dashboard/Footer";
import { SSRProvider } from "react-bootstrap";
Amplify.configure({ ...awsExports, ssr: true });
export const { serverRuntimeConfig, publicRuntimeConfig } = getConfig();
function App({ Component, pageProps }) {
return (
<SSRProvider>
<AuthContext>
<Header />
<Component {...pageProps} />
<Footer />
</AuthContext>
</SSRProvider>
)
}
export default appWithTranslation(App);
The test page (pages/test.js):
import { withSSRContext } from "aws-amplify";
export default function Test({user}) {
return <h5>{user}</h5>
}
export async function getServerSideProps({req}) {
const { Auth } = withSSRContext({ req });
try {
const user = await Auth.currentAuthenticatedUser();
return {
props: {
msg: user.username
},
};
} catch (err) {
console.log(err)
return {
props: {
msg: err
}
}
}
}
That's the error: "The user is not authenticated"
But if I use useEffect in function to retrieve user all is working good.
Oh wow! It's weird. Disabling Restrict access to app resolve the problem (https://docs.aws.amazon.com/amplify/latest/userguide/access-control.html).
Anyone that can answer scientifically?

Can’t get expoToken in Expo Notification, due to Failed resolution of: Lcom/google/firebase/iid/FirebaseInstanceId;

Good afternoon, hope you guys have a good day, i'm already building some apps using expo bare workflow, and need to use Expo Notification, i'm following all the instruction, from expo notification documentations, and fcm configurations, to setup firebase, but, when i'm tryin to get expoToken, i got this warning, looks like this:
Error: Encountered an exception while calling native method: Exception occurred while executing exported method getDevicePushTokenAsync on module ExpoPushTokenManager: Failed resolution of: Lcom/google/firebase/iid/FirebaseInstanceId;
and I've made sure that my package name is the same as the package I registered in firebase, can you guys help me? pleasee :slight_smile:
this is addtional information:
Getting Expo Token
const getToken = async () => {
console.log("TOKEN CHECK");
const { status: existingStatus } =
await Notifications.getPermissionsAsync();
let finalStatus = existingStatus;
if (existingStatus !== "granted") {
const { status } = await Notifications.requestPermissionsAsync();
finalStatus = status;
}
if (finalStatus !== "granted") {
alert("Failed to get push token for push notification!");
return;
}
token = (await Notifications.getExpoPushTokenAsync()).data;
console.log(token);
};
App.js
{
"name": "myapp",
"displayName": "myapp",
"expo": {
"name": "myapp",
"slug": "myapp",
"version": "1.0.0",
"assetBundlePatterns": [
"**/*"
]
},
"android": {
"googleServicesFile": "./google-services.json",
"useNextNotificationsApi": true
}
}
Package.json
{
"main": "index.js",
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"web": "expo start --web",
"start": "react-native start"
},
"dependencies": {
"#dudigital/react-native-zoomable-view": "^1.0.16",
"#react-native-async-storage/async-storage": "^1.15.5",
"#react-native-community/masked-view": "^0.1.11",
"#react-native-community/netinfo": "^6.0.0",
"#react-native-firebase/app": "^12.0.0",
"#react-native-firebase/firestore": "^12.0.0",
"#react-native-firebase/storage": "^12.0.0",
"#react-native-picker/picker": "^1.16.1",
"#react-navigation/material-bottom-tabs": "^5.3.15",
"#react-navigation/native": "^5.9.4",
"#react-navigation/stack": "^5.14.5",
"expo": "~41.0.1",
"expo-av": "~9.1.2",
"expo-image-manipulator": "~9.1.0",
"expo-image-picker": "~10.1.4",
"expo-notifications": "~0.11.6",
"expo-splash-screen": "~0.10.2",
"expo-status-bar": "~1.0.4",
"expo-updates": "~0.5.4",
"expo-web-browser": "~9.1.0",
"firebase": "^8.6.5",
"moment": "^2.29.1",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-native": "~0.63.4",
"react-native-calendars": "^1.1263.0",
"react-native-custom-qr-codes-expo": "^2.2.0",
"react-native-datepicker": "^1.7.2",
"react-native-gesture-handler": "~1.10.2",
"react-native-linear-gradient": "^2.5.6",
"react-native-orientation-locker": "^1.3.1",
"react-native-paper": "^4.9.1",
"react-native-raw-bottom-sheet": "^2.2.0",
"react-native-reanimated": "~2.1.0",
"react-native-render-html": "^5.1.1",
"react-native-responsive-screen": "^1.4.2",
"react-native-safe-area-context": "^3.2.0",
"react-native-screens": "~3.0.0",
"react-native-shimmer-placeholder": "^2.0.7",
"react-native-svg": "12.1.0",
"react-native-unimodules": "~0.13.3",
"react-native-vector-icons": "^8.1.0",
"react-native-web": "~0.13.12",
"react-native-webview": "^11.6.2"
},
"devDependencies": {
"#babel/core": "^7.9.0"
},
"private": true
}
screenshot:
someImages
You have to do two things:
In bare workflow, the Notifications.getExpoPushTokenAsync() method needs to provide the experienceId attributes.
const expoPushToken = await Notifications.getExpoPushTokenAsync({ experienceId });
console.log({ expoPushToken });
return expoPushToken.data;
You have to modify your /android/app/build.gradle to add 'com.google.firebase:firebase-iid:17.0.2'
dependencies {
implementation 'com.google.firebase:firebase-iid:17.0.2'
...
}

Dialogflow Webhook Firestore returns webhook failed status code 04, How to fix and get output from the firestore?

I am trying to integrate dialogflow with firestore but I can't get the required output. Diagnostic Info provides the below error. I need to get the response from the firestore according to the given input from the agent that's the basic requirement but I get this error while integrating.
{
"responseId": "a6a119a8-c406-4af2-aab0-b6863fb091a4-59c3eb0f",
"queryResult": {
"queryText": "15APC2375",
"parameters": {
"regno": "15APC2375"
},
"allRequiredParamsPresent": true,
"intent": {
"name": "projects/cis-bot-yhrvph/agent/intents/e3b1292b-89b1-48b7-b4b4-805a63d08168",
"displayName": "request-results"
},
"intentDetectionConfidence": 0.3,
"diagnosticInfo": {
"webhook_latency_ms": 4892
},
"languageCode": "en"
},
"webhookStatus": {
"code": 4,
"message": "Webhook call failed. Error: DEADLINE_EXCEEDED."
}
}
My Package.json includes the below code.
{
"name": "dialogflowFirebaseFulfillment",
"description": "This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
"engines": {
"node": "10"
},
"scripts": {
"start": "firebase serve --only functions:dialogflowFirebaseFulfillment",
"deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment"
},
"dependencies": {
"firebase": "^7.13.2",
"actions-on-google": "^2.2.0",
"firebase-admin": "^5.13.1",
"firebase-functions": "^2.0.2",
"dialogflow": "^0.6.0",
"dialogflow-fulfillment": "^0.5.0"
}
}
As well as index.js includes the below code.
'use strict';
const firebase = require('firebase');
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
admin.initializeApp();
const db = admin.firestore();
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
function welcome(agent) {
agent.add(`Welcome to CIS BOT!`);
}
function fallback(agent) {
agent.add(`Please Contact the Front Desk for more information`);
}
function getResults(agent){
const regno=agent.parameters.regno;
const dialogflowAgentDoc = db.collection('results').where("reg_id","==",'15APC2375')
.get()
.then((querySnapshot) => {
querySnapshot.forEach((doc) => {
// doc.data() is never undefined for query doc snapshots
agent.add(doc.data().grade);
});
}).catch(() => {
agent.add('Error reading entry from the Firestore database.');
agent.add('Please add a entry to the database first by saying, "Write <your phrase> to the database"');
});
}
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
intentMap.set('request-results', getResults);
// intentMap.set('your intent name here', googleAssistantHandler);
agent.handleRequest(intentMap);
});

How to fix error import Vue from 'vue' results in SyntaxError: Unexpected identifier

I'm trying to setup a test framework for a Vue.js project that I'm working on. I'm trying to use Jest for this but I end up with an error I don't seem to find a solution for. When I'm trying to run the tests, I get a syntax error in the terminal.
The error I'm getting is:
Test suite failed to run
Import Vue from 'vue';
^^^
SyntaxError: Unexpected identifier"
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
I've been looking around but I can't find a solution that helps me..
When removing the import of Vue, the test passes.
I run the tests by command npm run tests
// package.json
{
"name": "mlink-pwa",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"tests": "NODE_ENV=testing vue-cli-service test:unit"
},
"dependencies": {
"chart.js": "^2.7.3",
"chartjs-plugin-labels": "^1.1.0",
"countup.js": "^1.9.3",
"dexie": "^2.0.4",
"gauge-chart": "^0.4.3",
"moment": "^2.22.2",
"progressbar.js": "^1.0.1",
"raven-js": "^3.27.0",
"register-service-worker": "^1.5.2",
"vue": "^2.5.17",
"vue-countup-v2": "^2.0.0",
"vue-i18n": "^8.3.2",
"vue-router": "^3.0.2",
"vuedraggable": "^2.16.0",
"vuelidate": "^0.7.4",
"vuex": "^3.0.1"
},
"devDependencies": {
"#babel/preset-env": "^7.3.1",
"#vue/cli": "^3.1.3",
"#vue/cli-plugin-babel": "^3.1.1",
"#vue/cli-plugin-e2e-nightwatch": "^3.4.0",
"#vue/cli-plugin-eslint": "^3.1.5",
"#vue/cli-plugin-pwa": "^3.1.2",
"#vue/cli-plugin-unit-jest": "^3.4.0",
"#vue/cli-service": "^3.1.4",
"#vue/eslint-config-standard": "^4.0.0",
"#vue/test-utils": "^1.0.0-beta.25",
"babel": "^6.23.0",
"babel-core": "7.0.0-bridge.0",
"babel-jest": "^24.1.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
"eslint-plugin-jasmine": "^2.10.1",
"jasmine": "^3.3.1",
"node-sass": "^4.10.0",
"sass-loader": "^7.1.0",
"vue-jest": "^3.0.2",
"vue-template-compiler": "^2.5.17"
}
}
// jest.config.js
module.exports = {
moduleFileExtensions: ['js', 'json', 'vue'],
transform: {
'^.+\\.jsx?$': 'babel-jest',
'^.+\\.vue$': 'vue-jest'
},
clearMocks: true,
coverageDirectory: "coverage",
};
// babel.config.js
module.exports = {
env: {
testing: {
presets: [
['env', { modules: false }],
'#babel/preset-env',
'#vue/app'
],
plugins: [
'transform-es2015-modules-commonjs'
]
}
}
}
// first.spec.js - THIS FAILS
import Vue from 'vue'
describe('', () => {
it('first test', () => {
expect(true).toEqual(true);
});
});
// first.spec.js - THIS PASSES
describe('', () => {
it('first test', () => {
expect(true).toEqual(true);
});
});
Expected:
I expect the test suite to run and the test to pass.
Actual:
The test suite does not run.
This is a problem with a particular version of vue-cli. Installing the latest and starting a new project resolves the issue. Or alternately do this in a "mock" project and copy all the npm dependency versions over to your existing project.

Trigger Multiple Dataflow job through Cloud function in Synchronized manner?

I have to trigger multiple templates one by one using Google Cloud function in Google Dataflow Process. After execution of one template, the another template must be called.
const google = require('googleapis');
exports.goWithTheDataFlow = function(event, callback) {
const file = event.data;
if (file.resourceState === 'exists' && file.name) {
google.auth.getApplicationDefault(function (err, authClient, projectId) {
if (err) {
throw err;
}
if (authClient.createScopedRequired && authClient.createScopedRequired()) {
authClient = authClient.createScoped([
'https://www.googleapis.com/auth/cloud-platform',
'https://www.googleapis.com/auth/userinfo.email'
]);
}
const dataflow = google.dataflow({ version: 'v1b3', auth: authClient });
dataflow.projects.templates.create({
projectId: 'testing1-180111',
resource: {
parameters: {
},
jobName: 'cloud-fn-dataflow-test',
gcsPath: 'gs://kishan-configuration/templates/FinalConfigTable'
}
}, function(err, response) {
if (err) {
console.error("problem running dataflow template, error was: ", err);
}
console.log("Dataflow template response: ", response);
callback();
});
});
}
};
package.json file code is this
{
"name": "kishan_kumar464",
"version": "1.0.0",
"main": "index.js",
"dependencies": {
"google-cloud": "^0.56.0",
"googleapis": "^22.2.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Kishan",
"license": "ISC",
"description": ""
}
If I understand correctly, you'd like to create a job from a template and wait until finish. After that, you can create the next job from the template. Correct?
I think you can probably poll the job status after the job is created (job id is in the response of dataflow.projects.templates.create.
To check the status of a job, please use projects.jobs.get API.