TypeError: Cannot access member 'match' of undefined - web3js

I can't call the functions of the metaCoin contract on my private chain within the geth console from another added peer node.
I've deployed the metaCoin contract byTruffle on my computer,
https://truffleframework.com/docs/truffle/getting-started/interacting-with-your-contracts
and I'm trying to call the functions from another node linked together on my private chain.
I've only managed to find the exact same problem described here, but my version of Web3.js is already 1.0.0-beta.55
https://github.com/ethereum/web3.js/issues/898
Here is the code I tried so far
$ mkdir web3test && cd web3test
$ npm init
$ npm install web3 --save
var Web3 = require("web3");
var web3 = new Web3();
web3.setProvider(new Web3.providers.HttpProvider("http://localhost:8545"));
var abi = [myabi}];
var address = "myaddress";
var metacoin = web3.eth.contract(abi).at(address);
var account_one = web3.eth.accounts[0];
var account_one_balance = metacoin.getBalance.call(account_one);
https://my.oschina.net/u/2349981/blog/863731
This is the message I'm getting whenever I type in metacoin.getBalance.call(account_one)
TypeError: Cannot access member 'match' of undefined
at web3.js:539:14
at web3.js:660:16
at filter ()(<native code>)
at web3.js:659:24
at web3.js:850:16
at map ()(<native code>)
at web3.js:849:12
at web3.js:691:25
at web3.js:4059:46
at web3.js:4098:19

Related

I want to use ?. in a React project but it throws an error

I'm facing a problem with React. If I use ?. it throws an error
Module parse failed: Unexpected token (21:22)
You may need an appropriate loader to handle this file type.
| var navigate = useNavigate();
| var location = useLocation();
> var from = location?.state?.from?.pathname || "/";
| var userRef = React.useRef();
| var errRef = React.useRef();
How can I solve this?
You'll need to either upgrade to webpack 5 or use #babel/plugin-proposal-optional-chaining
Reference: Webpack issues
The Optional Chaining ?. operator wasn't added to Node until version 14. Make sure you have the right version installed. You can check which version of node you are using with node -v
You could also use a transcompiler like Babel which will implement unsupported features to make your code 'backwards compatible'
See: https://babeljs.io/docs/en/babel-plugin-syntax-optional-chaining.html

console error when running npm start command in new react project

I would like you to help me repair an error that I have, is that every time I create a new project in react with the command npx create-react-app app-name and followed by a cd to the directory and an npm start, I says everything is correct:
Compiled successfully!
You can now view cacas in the browser.
Local: http://localhost:3000
On Your Network: http://172.27.248.214:3000
Note that the development build is not optimized.
To create a production build, use yarn build.
enter image description here
Followed by this I go to the browser, and I give f12 to start the inspector, and I run into the following errors:
First error
Error handling response: SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse (<anonymous>)
at chrome-extension://bmjmipppabdlpjccanalncobmbacckjn/js/content/content.js:60:21
According to the error is in this line
data = JSON.parse(data.cs_template);
Full code shown
document.addEventListener('DOMContentLoaded', function () {
for (var i = 0; i < blacklist.length; i++) {
if (location.href.search(blacklist[i]) > 0)
return;
}
cStyle = document.createElement('style');
cStyle.id = 'cs_cursor_css_no_hd';
document.head.appendChild(cStyle);
if (!document.getElementById('elem_ext')) {
elem_ext = document.createElement('div');
elem_ext.id = 'elem_ext';
elem_ext.style.display = 'none';
document.documentElement.appendChild(elem_ext);
}
chrome.storage.local.get('storage_data', function (data) {
if (localStorage.hasOwnProperty('storage_data'))
localStorage.removeItem('storage_data');
localStorage.setItem('storage_data', data.storage_data);
document.documentElement.dataset.csCursorMode = hd_mode;
insert_cs_script();
})
chrome.storage.local.get('cs_template', function (data) {
data = JSON.parse(data.cs_template);
js = document.createElement('script');
js.id = 'cs_cursor_template';
js.innerHTML = data.template;
document.head.appendChild(js);
});
})
Image showing what I already wrote above
enter image description here
Second error
Uncaught SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse (<anonymous>)
at main.js:97
The error sends me to this part of code
var storage_data = (localStorage.hasOwnProperty('storage_data')) ? JSON.parse(localStorage.getItem('storage_data')) : {};
enter image description here
Third error
Uncaught ReferenceError: showCsCursorNonHD is not defined
at <anonymous>:1:35
The third error shows me this
cs_hd_mode = false; showCsCursorNonHD(); hideCsCursor();
enter image description here
It is a new project, without any change
enter image description here
Directories
enter image description here
enter image description here
I have been using WSL2 for more than a year and about a month ago these errors began to appear when creating a new project in react
I believe the issue is that you are trying to call JSON.parse(...) on something that is already a JS object. your data in the callback to chrome.storage.local.get('cs_template',...) is already a JS object. I am not sure what the structure of your data is, but data should be the actual cs_template object that can be accessed like data.cs_template in the callback function.

Cannot add Firebase library to Apps Script

I want to sync a Google Sheet with my Firebase real-time database.
My code is:
function writeDataToFirebase() {
var ss =
SpreadsheetApp.openById("18AU9ZP9UHs9lvIeTA0SyJv6tcHPe7ux0tLopkRAz1T0");
var sheet = ss.getSheets()[0];
var data = sheet.getDataRange().getValues();
var dataToImport = {};
for(var i = 2; i < data.length; i++) {
var date = data[i][1];
dataToImport[date] = {
niftyclose:data[i][2],
sensexclose:data[i][5]
};
}
var firebaseUrl = "<MY database URL>"; //Yes I have entered the URL in my actual code
var base = FirebaseApp.getDatabaseByUrl(firebaseUrl);
base.setData("", dataToImport);
}
But when I run the script, I get this error:
ReferenceError: FirebaseApp is not defined
I tried adding the Firebase Library and got this error:
Firebase Library Error
Can someone help me figure this out?
Thanks in advance.
I think that MYeP8ZEEt1ylVDxS7uyg9plDOcoke7-2l is the project key. In this case, it can be used for the legacy editor. But, in the current stage, the script ID is used for installing the GAS library. And also, when you use new script editor, it is required to use the script ID for installing the library. I thought that this is the reason of your issue.
When the project key of MYeP8ZEEt1ylVDxS7uyg9plDOcoke7-2l is installed using the the legacy editor and check appsscript.json, the script ID of the library can be known. It's 1hguuh4Zx72XVC1Zldm_vTtcUUKUA6iBUOoGnJUWLfqDWx5WlOJHqYkrt. So please modify your situation as follows.
1hguuh4Zx72XVC1Zldm_vTtcUUKUA6iBUOoGnJUWLfqDWx5WlOJHqYkrt
Please install the library using above script ID. This script ID can be also seen at https://sites.google.com/site/scriptsexamples/new-connectors-to-google-services/firebase/source
References:
Libraries
Firebase

#firebase/database: FIREBASE WARNING: Exception was thrown by user callback. TypeError: Cannot read property 'myID' of undefined

I just built an angularjs app using geofire for location. It works perfectly in production but has issues when i deploy it to firebase. I believe the error should be from here
getLocations(radius: number, coords: Array<number>) {
console.log(radius, coords)
this.geoFire.query({
center: coords,
radius: radius
})
.on('key_entered', (userKey, location, distance) => {
//we need to check this because this.hits the behavioursubject already cached previous result and geofire fetches again each time we go back to homepage
const existAlready = this.hits.value.filter(h=>h.userKey === userKey)
if(existAlready.length > 0){
return
}
console.log(userKey)
const u = this.userList.query.ref
.child(`/${userKey}`)
.on('value',s=>{
const {name, address} = s.val()
console.log(s.val())
let hit = {
location,
distance,
name,
address,
userKey
}
let currentHits = this.hits.value
currentHits.push(hit)
this.hits.next(currentHits)
this.eventService.sendMessage(Constants.EVENT_MESSAGES.LOADING, true)
})
})
}
The above code is meant to fetch the locations around me as soon as the app loads. But instead i get this error
#firebase/database: FIREBASE WARNING: Exception was thrown by user
callback. TypeError: Cannot read property 'myID' of undefined
The error only comes in production
I have corrected the error with the following versions of libraries
npm uninstall firebase
npm uninstall angularfire2
npm install firebase#^4.11.0
npm install angularfire2#^5.0.0-rc.6
I am getting this same error in production in my application as well. The only thing that seems to fix it is clearing my google cache, history, and cookies. It isn't a permanent fix in the slightest, but try and see if it helps.
Not sure if that's the solution but that worked for me. I think the real problem happens once you deploy a new build and not clear the cache.
So for me, eveytime i deploy, i have to clear the cache again.
interesting enough, this just happens in chrome. I tested it in Edge and i don't have to go through that.

Using chance.js inside AngularJS end to end tests

I'm trying to generate some random data for my e2e tests. Seems that the only library I found was chance.js. But can't make it works. This is what I've tried so far:
describe('In the login page', function () {
var chance = new Chance(); // ReferenceError: Chance is not defined
}
Then adding
beforeEach(function(){
browser.executeScript(
function() {
return chance;
}).then(function(_chance){
chance = _chance; //It returns an object, but can't use any of the methods.
});
});
But if I try
beforeEach(function(){
browser.executeScript(
function() {
return chance.email(); //Note this line here
}).then(function(_chance){
chance = _chance; //It returns an email
});
});
Thats all I have so far... any clue/idea?
First, install chance.js in your project:
npm install chance --save-dev
This installs chance.js as a node module in your project. Then include it in your spec and instantiate:
var chance = require('../node_modules/chance').Chance();
Then call in your spec. For example:
it('should add a new friend', function() {
var friendName = chance.string()
friendPage.addFriend(friendName);
expect(friendPage.inResults(friendName)).toBeTruthy();
});
Hope that helps...
Okay first you need to download chance.js and add that file to your html directory
Second add script src="chance.js" in a proper script tag your section
Within another script tag you should be able to use any of the functions that are listed on the website
working jsfiddle: http://jsfiddle.net/c96x2cpa/
fiddle js code:
alert(chance.bool());
alert(chance.character());
alert(chance.floating());
It was easy at the end :)
You just need to install chance as a node module.
npm install chance
Then require the node in the spec
// Load Chance
var Chance = require('chance');
And use it where ever you want
chance.email()
Enjoy!

Resources