Error Unable to resolve module `http` from web3-providers.umd.js - expo

I installed web3 to link Solidity to React-native. As in the code below, I deployed it from Remix and entered the address and ABI.
import Web3 from "web3";
const web3 = new Web3(
new Web3.providers.HttpProvider("https://127.0.0.1:8545")
);
const address = "0x6cc33e32853a7fb0ac9ac2fb0d54cb56e4fb0f30";
const abi = [
{
constant: false,
inputs: [
{
name: "_MASTER",
type: "address"
},
{
name: "_sitter",
type: "address"
},
{
name: "_sitterprice",
type: "uint256"
}
],
name: "CompleteSharePet",
outputs: [],
payable: true,
stateMutability: "payable",
type: "function"
},
{
constant: false,
inputs: [
{
name: "_OWNER",
type: "address"
},
{
name: "_ownersharetext",
type: "string"
},
{
name: "_ownerprice",
type: "uint256"
}
],
name: "OwnerShareText",
outputs: [
{
name: "",
type: "string"
}
],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: false,
inputs: [
{
name: "_ownerseller",
type: "address"
},
{
name: "_petsitter",
type: "address"
},
{
name: "_MASTER",
type: "address"
},
{
name: "_ownerprice",
type: "uint256"
}
],
name: "PetChange",
outputs: [],
payable: true,
stateMutability: "payable",
type: "function"
},
{
constant: false,
inputs: [
{
name: "_PETSITTER",
type: "address"
},
{
name: "_master",
type: "address"
},
{
name: "_ownerprice",
type: "uint256"
}
],
name: "PetChangeTransaction",
outputs: [],
payable: true,
stateMutability: "payable",
type: "function"
},
{
constant: false,
inputs: [
{
name: "_petsittertext",
type: "string"
},
{
name: "_sitterprice",
type: "uint256"
}
],
name: "PetSitterShareText",
outputs: [
{
name: "",
type: "string"
}
],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: false,
inputs: [
{
name: "_sitter",
type: "address"
}
],
name: "testsitter",
outputs: [],
payable: true,
stateMutability: "payable",
type: "function"
},
{
constant: false,
inputs: [
{
name: "_master",
type: "address"
},
{
name: "_OWNER",
type: "address"
},
{
name: "_sitterprice",
type: "uint256"
}
],
name: "TransactionSharePet",
outputs: [],
payable: true,
stateMutability: "payable",
type: "function"
},
{
constant: false,
inputs: [
{
name: "hash",
type: "string"
},
{
name: "ipfs",
type: "string"
}
],
name: "uploadImage",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: true,
inputs: [],
name: "AllOwnerCount",
outputs: [
{
name: "",
type: "uint256"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [],
name: "AllPetSitter",
outputs: [
{
name: "",
type: "uint256"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [],
name: "getOwnerAddresses",
outputs: [
{
name: "",
type: "address[]"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [
{
name: "_owner",
type: "address"
}
],
name: "getOwnerInfo",
outputs: [
{
name: "",
type: "string"
},
{
name: "",
type: "string"
},
{
name: "",
type: "string"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [],
name: "getPetSitterAddresses",
outputs: [
{
name: "",
type: "address[]"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [
{
name: "_petsitter",
type: "address"
}
],
name: "getPetSitterInfo",
outputs: [
{
name: "",
type: "string"
},
{
name: "",
type: "string"
},
{
name: "",
type: "string"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [
{
name: "",
type: "uint256"
}
],
name: "OwnerAddresses",
outputs: [
{
name: "",
type: "address"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [
{
name: "",
type: "uint256"
}
],
name: "PetSitterAddresses",
outputs: [
{
name: "",
type: "address"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [
{
name: "_OWNER",
type: "address"
}
],
name: "test",
outputs: [
{
name: "",
type: "uint256"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [
{
name: "_MASTER",
type: "address"
}
],
name: "test2",
outputs: [
{
name: "",
type: "uint256"
}
],
payable: false,
stateMutability: "view",
type: "function"
}
];
export class WalletSetting extends Component {
test() {
web3.eth.getAccounts().then(console.log);
}
render() {
return this.test;
}
}
export default (myContract = new web3.eth.Contract(abi, address));
The setting was error-free, but the error occurred when import was made to use mycontact
import WalletSetting from "../web3";
.
.
.
</TouchableOpacity>
<WalletSetting />
</LinearGradient>
Error Image
I deleted all the node_modules and all the cache, just like the way in the picture. However, the same error occurred.
I downloaded the web3 version as "^1.0.0-beta.34" to resolve the existing error, but another error occurred.
Error is
Unable to resolve module crypto from /Users/lucky/pettest/node_modules/web3-eth-accounts/src/index.js: Module crypto does not exist in the Haste module map
So I went to Google for reference https://gist.github.com/dougbacelar/29e60920d8fa1982535247563eb63766
And install "node-libs-browser": "^2.2.0", "babelpresetes2015":"^6.24.1",
and create a file called rn-cli.config.js, global.js and import the globaljs file into your web3.js file, but the error was the same.
How can I fix this?
https://gist.github.com/dougbacelar/29e60920d8fa1982535247563eb63766
This linked solution will not solve my problem.

web3 was made to work in a browser environment. The native android environment is different than that of a browser, for example, it doesn't have the crypto class that web3 uses. Using web3 with react native will require some extra configuration. You can follow this guide: https://gist.github.com/dougbacelar/29e60920d8fa1982535247563eb63766.
Also you can find a boilerplate here: https://github.com/dougbacelar/react-native-web3

I have a solution to part of your problem, regarding crypto. Install react-native-crypto and save it as a dependency, then babel-plugin-module-resolver as a dev-dependency, and put a .babelrc file in your project root that contains something like this:
{
"plugins": [
["module-resolver", {
"root": ["."],
"alias": {
"crypto": "react-native-crypto"
}
}]
]
}
This replaces any require('crypto') in your installed packages with require('react-native-crypto'), and it worked for me. In my case however, the same package I had that was missing crypto is also missing http so I came to this thread to hopefully find a polyfill for that too. I am on RN v0.60.3, npm v6.9.0, and node v10.16.0 for anyone interested. Also the package I needed this 'shim' for is the request package, which seems to be a sub-sub-sub-sub-dependency of jest. (npm list request).
I hope this helps somebody!
I found this solution here: https://stackoverflow.com/a/46605706/12375465
and here: https://medium.com/studioarmix/the-joy-of-joi-hacking-node-deps-1337fd5e586f

Related

Adding organization and app in serverless.ts breaks the application

i am experiencing very strange behaviour with my serverless application,
here is my serverless.ts file
import type { AWS } from '#serverless/typescript';
import {
hello,
} from '#functions';
const serverlessConfiguration: AWS = {
service: 'users',
frameworkVersion: '2',
// org: '<MY-ORG-NAME>',
// app: '<MY-APP-NAME>',
custom: {
esbuild: {
bundle: true,
minify: false,
sourcemap: true,
exclude: ['aws-sdk'],
target: 'node14',
define: { 'require.resolve': undefined },
platform: 'node',
},
'serverless-offline': {
httpPort: 4000,
},
ngrokTunnel: {
tunnels: [
{
port: 4000,
},
],
},
avatarUploadBucket: '<NAME>',
userReplicationTopic: '<NAME>',
replicatedUserRemovalTopic:
'<NAME>',
},
plugins: [
'serverless-esbuild',
'serverless-offline',
'serverless-ngrok-tunnel',
],
provider: {
name: 'aws',
runtime: 'nodejs14.x',
profile: '<MY-AWS-PROFILE>',
region: '<MY-REGION>',
stage: 'dev',
apiGateway: {
minimumCompressionSize: 1024,
shouldStartNameWithService: true,
},
iamRoleStatements: [
{
Effect: 'Allow',
Action: ['s3:*', 'sns:*'],
Resource: '*',
},
],
environment: {
AWS_NODEJS_CONNECTION_REUSE_ENABLED: '1',
NODE_OPTIONS: '--enable-source-maps --stack-trace-limit=1000',
USER_REPLICATION_TOPIC_ARN: {
Ref: 'UserReplicationSNSTopic',
},
REPLICATED_USER_REMOVAL_TOPIC_ARN: {
Ref: 'ReplicatedUserRemovalSNSTopic',
},
},
lambdaHashingVersion: '20201221',
},
functions: {
hello
},
resources: {
Resources: {
AvatarUploadBucket: {
Type: 'AWS::S3::Bucket',
Properties: {
BucketName: '${self:custom.avatarUploadBucket}',
AccessControl: 'PublicRead',
},
},
UserReplicationSNSTopic: {
Type: 'AWS::SNS::Topic',
Properties: {
TopicName: '${self:custom.userReplicationTopic}',
},
},
ReplicatedUserRemovalSNSTopic: {
Type: 'AWS::SNS::Topic',
Properties: {
TopicName: '${self:custom.replicatedUserRemovalTopic}',
},
},
},
},
outputs: {
snsTopics: {
ReplicatedUserRemovalSNSTopicARN: '!Ref ReplicatedUserRemovalSNSTopic',
},
},
};
module.exports = serverlessConfiguration;
i currently have org and app commented out and it works but if i uncomment them, and send request to the api endpoint i get following error Runtime.ImportModuleError: Error: Cannot find module 's_hello'
it is not about the contents of file since i get this error for every microservice i have and for every function in that microservice, for this commented out version, this is the handler (in aws console)
but if i uncomment it, this is the result
why does this happen?
P.S: I can see the upload also happen in serverless dashboard.

How to import swagger/?format=openapi to postman from django-rest-swagger without error of format not recognized

Our project use django-rest-swagger to manage API, and we would like to export all api and import Postman, I can get JSON by below url localhost:5000/swagger/?format=openapi, but when I import the file, postman says Error while importing: format not recognized, How to import swagger/?format=openapi to postman from django-rest-swagger without error of format not recognized?
Is there anyone who knows some easy way to solve it? Thanks so much for any advice!!!!!
{
swagger: "2.0",
info: {
title: "TestProjectAPI",
description: "",
version: ""
},
host: "localhost:5000",
schemes: [
"http"
],
paths: {
/api-token/: {
post: {
operationId: "api-token_post",
responses: {
201: {
description: ""
}
},
parameters: [
{
name: "data",
in: "body",
schema: {
type: "object",
properties: {
pic_id: {
description: "",
type: "string"
},
phonenumber: {
description: "",
type: "string"
},
checkcode: {
description: "",
type: "string"
},
user_phone: {
description: "",
type: "string"
},
phone_code: {
description: "",
type: "string"
},
username: {
description: "",
type: "string"
},
password: {
description: "",
type: "string"
}
}
}
}
],
description: "User Login",
summary: "User Login",
consumes: [
"application/json"
],
tags: [
"api-token"
]
}
},
/porject_management/: {
get: {
operationId: "porject_management_list",
responses: {
200: {
description: ""
}
},
parameters: [
{
name: "page",
required: false,
in: "query",
description: "A page number within the paginated result set.",
type: "integer"
},
{
name: "page_size",
required: false,
in: "query",
description: "Number of results to return per page.",
type: "integer"
},
{
name: "search",
required: false,
in: "query",
description: "A search term.",
type: "string"
},
{
name: "project",
required: false,
in: "query",
description: "",
type: "string"
},
{
name: "state",
required: false,
in: "query",
description: "",
type: "number"
},
{
name: "ordering",
required: false,
in: "query",
description: "Which field to use when ordering the results.",
type: "string"
}
],
description: "porject management",
summary: "porject management",
tags: [
"porject_management_post"
]
},
post: {
operationId: "porject_management_post",
responses: {
201: {
description: ""
}
},
parameters: [
{
name: "data",
in: "body",
schema: {
type: "object",
properties: {
project: {
description: "",
type: "string"
},
tc_code: {
description: "",
type: "string"
},
visitors_number: {
description: "",
type: "integer"
},
site_selection: {
description: "",
type: "string"
},
contact_name: {
description: "",
type: "string"
},
contact_number: {
description: "",
type: "string"
},
remark: {
description: "",
type: "string"
},
type: {
description: "",
type: "integer"
},
state: {
description: "",
type: "integer"
},
status: {
description: "",
type: "integer"
},
creater: {
description: "",
type: "string"
},
modifier: {
description: "",
type: "string"
}
}
}
}
],
description: "Porject management",
summary: "Porject management",
consumes: [
"application/json"
],
tags: [
"homemanager"
]
}
},
securityDefinitions: {
basic: {
type: "basic"
}
}
}
Have you tried using:
python3 manage.py generateschema --file openapi-schema.yml
in terminal? Then you can directly import the schema to your POSTMAN. You are providing JSON format, use yaml format for postman it should work.
Finally, I solved my problem by eolink.com,
Firstly, import JSON from localhost:5000/swagger/?format=openapi
Secondly, export Swagger by eolink.com, and then you can import that file to postman!!!

How to get string between two tags

I would like to get demo object from string file:
But looks like that my regexp is wrong: (demo: \[)(.*)(\],)
sayHello(() => ({
foo: eeeeeeeeeeeeee,
demo: [
{
name: 'abcd',
},
{
name: 'qqqq',
},
],
}));
Expected output:
[
{
name: 'abcd',
},
{
name: 'qqqq',
},
]

Loopback js can't read GET request params in the url

I have the following code:
Addresses.getorderHistory = function(address, baseToken, status, length, cb) {
console.log("lenght here -> " + length);
addressService.getorderHistory(address, baseToken, status, length, cb)
.catch(err => cb(err));
};
Addresses.remoteMethod('getorderHistory', {
http: { verb: 'get', path: '/:address/orderHistory' },
accepts: [
{ arg: "address", type: "string", required: true },
{ arg: "base_token", type: "string", required: true, 'http': {source: 'query'} },
{ arg: "status", type: "string", required: true, 'http': {source: 'query'} },
{ arg: "length", type: "string", required: true, 'http': {source: 'query'} }
],
returns: { type: 'object', root: true }
});
When I make a request like this
curl http://localhost:3001/<my root>/addresses/<my address>/orderHistory?base_token=<my token>&status=filled&length=100
It says
Error: status is a required argument
I can basically read address and baseToken values but I can't read status and length. What am I missing?

Google Freebase API How To Get URL Of Image?

So, I am trying to figure out how to get URL to an image in Freebase database. I want an image of San Francisco. This is how I get the San Francisco topic:
https://www.googleapis.com/freebase/v1sandbox/topic/%2Fen%2Fsan_francisco?key=MY_API_KEY
The response contains images, for example:
{
text: "San Francisco Skyline",
lang: "en",
id: "/m/04j74yh",
creator: "/user/carmenmfenn1",
timestamp: "2008-09-01T13:37:22.000Z"
}
So I then call the GET API again to get the image:
https://www.googleapis.com/freebase/v1sandbox/topic/%2Fm%2F04j74yh?key=MY_API_KEY
This returns lots of information about the image such as media type, size etc. But I don't see any URL there. There are some IDs (blob id, mid). I am not sure how to proceed to get a URL to the image. Any ideas?
This is the full response:
{
id: "/m/04j74yh",
property: {
/common/image/appears_in_topic_gallery: {
valuetype: "object",
values: [
{
text: "San Francisco",
lang: "en",
id: "/m/0d6lp",
creator: "/user/carmenmfenn1",
timestamp: "2008-09-01T13:37:22.000Z"
}
],
count: 1
},
/common/image/size: {
valuetype: "compound",
values: [
{
text: "640.0 - 330.0 - Freebase Data Team - Rectangle Size",
lang: "en",
id: "/m/02bpzld",
creator: "/user/carmenmfenn1",
timestamp: "2008-09-01T13:37:22.000Z",
property: {
/measurement_unit/rect_size/x: {
valuetype: "float",
values: [
{
text: "640.0",
lang: "en",
value: 640,
creator: "/user/mwcl_images",
timestamp: "2007-04-15T23:03:01.001Z"
}
],
count: 1
},
/measurement_unit/rect_size/y: {
valuetype: "float",
values: [
{
text: "330.0",
lang: "en",
value: 330,
creator: "/user/mwcl_images",
timestamp: "2007-04-15T23:03:01.001Z"
}
],
count: 1
},
/type/object/attribution: {
valuetype: "object",
values: [
{
text: "Freebase Data Team",
lang: "en",
id: "/m/0220tm0",
creator: "/user/mwcl_images",
timestamp: "2007-04-15T23:03:01.001Z"
}
],
count: 1
},
/type/object/type: {
valuetype: "object",
values: [
{
text: "Rectangle Size",
lang: "en",
id: "/measurement_unit/rect_size",
creator: "/user/mwcl_images",
timestamp: "2007-04-15T23:03:01.001Z"
}
],
count: 1
}
}
}
],
count: 1
},
/common/licensed_object/license: {
valuetype: "object",
values: [
{
text: "CC-BY-2.5",
lang: "en",
id: "/m/01xrw11",
creator: "/user/carmenmfenn1",
timestamp: "2008-09-01T13:37:22.000Z"
}
],
count: 1
},
/common/topic/notable_for: {
valuetype: "object",
values: [
{
text: "Content",
lang: "en",
id: "/type/content"
}
],
count: 1
},
/common/topic/notable_types: {
valuetype: "object",
values: [
{
text: "Content",
lang: "en",
id: "/type/content",
timestamp: "2013-05-17T00:04:43.942Z"
}
],
count: 1
},
/type/content/blob_id: {
valuetype: "string",
values: [
{
text: "8debf723b25edb43b413bcb2890c4f4fe6ec5e5b2c7ce9c7e1f2aee273b0d0fe",
lang: "",
value: "8debf723b25edb43b413bcb2890c4f4fe6ec5e5b2c7ce9c7e1f2aee273b0d0fe",
creator: "/user/content_administrator",
timestamp: "2008-09-01T13:37:20.000Z"
}
],
count: 1
},
/type/content/length: {
valuetype: "int",
values: [
{
text: "47162",
lang: "en",
value: 47162,
creator: "/user/content_administrator",
timestamp: "2008-09-01T13:37:20.000Z"
}
],
count: 1
},
/type/content/media_type: {
valuetype: "object",
values: [
{
text: "image/jpeg",
lang: "en",
id: "/m/08x8",
creator: "/user/content_administrator",
timestamp: "2008-09-01T13:37:20.000Z"
}
],
count: 1
},
/type/object/attribution: {
valuetype: "object",
values: [
{
text: "Freebase Staff",
lang: "en",
id: "/m/05g",
creator: "/user/content_administrator",
timestamp: "2008-09-01T13:37:20.000Z"
}
],
count: 1
},
/type/object/mid: {
valuetype: "key",
values: [
{
text: "/m/04j74yh",
lang: "",
value: "/m/04j74yh"
}
],
count: 1
},
/type/object/name: {
valuetype: "string",
values: [
{
text: "San Francisco Skyline",
lang: "en",
value: "San Francisco Skyline",
creator: "/user/carmenmfenn1",
timestamp: "2008-09-01T13:42:34.000Z"
}
],
count: 1
},
/type/object/type: {
valuetype: "object",
values: [
{
text: "Image",
lang: "en",
id: "/common/image",
creator: "/user/content_administrator",
timestamp: "2008-09-01T13:37:20.000Z"
},
{
text: "Content",
lang: "en",
id: "/type/content",
creator: "/user/content_administrator",
timestamp: "2008-09-01T13:37:20.000Z"
}
],
count: 2
},
/type/object/guid: {
valuetype: "string",
values: [
{
text: "#9202a8c04000641f80000000090393af",
lang: "",
value: "#9202a8c04000641f80000000090393af"
}
],
count: 1
},
/type/object/creator: {
valuetype: "object",
values: [
{
text: "content_administrator",
lang: "",
id: "/user/content_administrator",
timestamp: "2008-09-01T13:37:20.000Z"
}
],
count: 1
},
/type/object/timestamp: {
valuetype: "datetime",
values: [
{
text: "2008-09-01T13:37:20.000Z",
lang: "en",
value: "2008-09-01T13:37:20.000Z"
}
],
count: 1
},
/type/object/permission: {
valuetype: "object",
values: [
{
text: "/boot/all_permission",
lang: "",
id: "/boot/all_permission"
}
],
count: 1
}
}
}
It's kind of buried in the documentation since it doesn't have a section of its own, but is instead referenced from the Topic API documentation, but you can find the necessary info here
URLs are of the form:
https://usercontent.googleapis.com/freebase/v1/image/<image ID>