How to generate mnemonics in Expo React app? - expo

Generating mnemonics phrases for a crypto wallet.
I've tried bip39 (npm i bip39) but it's not working on expo.
var bip39 = require('bip39')
const mnemonic = bip39.generateMnemonic()
console.log(mnemonic)

Related

Azure Web Job Console application config setting not getting overridden by Azure App Service Config setting

I'm running a Dot Net 6.0 Console application as a web job in Azure App Service. I want to override the configuration setting present in apsettings.json file by the one present in Azure App Service Configuration.
This is the code present in the console application to read the configuration
static async Task Main(string[] args)
{
var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json").Build();
var testKey = configuration.GetSection($"TestKey").Value;
Console.WriteLine($"TestKey {testKey}");
And this is apsettings.json file
{ "TestKey": "TestValue" }
Application setting in the Azure App Service where console app is deployed as a Web Job
Output from the Web Job
AFAIK, To override the configuration setting in apsettings.json file, add .AddEnvironmentVariables in Program.cs.
I have reproduced in my environment and got the expected results.
Program.cs
var config = new ConfigurationBuilder()
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables()
.Build();
var testKey = config.GetSection($"TestName").Value;
Console.WriteLine($"TestKey {testKey}");
appsettings.json
{
"TestName": "TestValue"
}
Application settings in Azure App Service(Portal):
Output:
Before adding .AddEnvironmentVariables:
After adding .AddEnvironmentVariables:

Provider not set or invalid. How to interact with smart contract without wallet?

I am developing a Web3 App using Solidity, smart contract is working perfect, after deploying it to web server, The app is working flawless on my PC but I faced an issue on my browsers that don't have Metamask wallet.
Error:
Error: Provider not set or invalid
at Object.InvalidProvider (errors.js:39:16)
at f.send (index.js:145:32)
at s (index.js:624:42)
at a.n [as getId] (index.js:656:13)
at Web3Client.js:197:39
at f (regeneratorRuntime.js:86:17)
at Generator._invoke (regeneratorRuntime.js:66:24)
at Generator.next (regeneratorRuntime.js:117:21)
at Ne (asyncToGenerator.js:3:20)
at a (asyncToGenerator.js:25:9)
React Code:
export const init = async () => {
let provider = window.ethereum;
if (typeof provider !== 'undefined') {
}
const web3 = new Web3(provider);
const networkId = await web3.eth.net.getId();
erc20Contract = new web3.eth.Contract(
erc20Abi,
addr
);
isInitialized = true;
};
What is the best and minimal way to interact with Smartcontracts without Wallet?
You can create account on https://infura.io then you get api key to communicate with blockchain. Copy url from infura, in result you should get response from provider. const web3 = new Web3('https://mainnet.infura.io/v3/YOUR-API-KEY ');
MetaMask comes with a built-in HTTPProvider for Infura JSON-RPC API.
You can register to any of the free JSON-RPC API provider services and get a personal JSON-RPC endpoint with an API key. Alternatively you can run your own Ethereum node.
You can also reverse engineer MetaMask and get their API key out from its JavaScript files.

Microsoft C++ Rest SDK for Graph APIs

I am trying out Microsoft's C++ Rest SDK (https://microsoft.github.io/cpprestsdk/index.html) to invoke Graph APIs but it has been a struggle so far.
In C# I can complete my tasks in a few lines of code. For example, refer following code from a Microsoft tutorial:
AuthenticationConfig config = AuthenticationConfig.ReadFromJsonFile("appsettings.json");
bool isUsingClientSecret = AppUsesClientSecret(config);
IConfidentialClientApplication app;
if (isUsingClientSecret)
{
app = ConfidentialClientApplicationBuilder.Create(config.ClientId)
.WithClientSecret(config.ClientSecret)
.WithAuthority(new Uri(config.Authority))
.Build();
}
string[] scopes = new string[] { $"{config.ApiUrl}.default" };
AuthenticationResult result = null;
try
{
result = await app.AcquireTokenForClient(scopes)
.ExecuteAsync();
}
catch (MsalServiceException ex) when (ex.Message.Contains("AADSTS70011"))
{
}
// config.ApiUrl is set to "graph.microft.com"
if (result != null)
{
var httpClient = new HttpClient();
var apiCaller = new ProtectedApiCallHelper(httpClient);
await apiCaller.CallWebApiAndProcessResultASync($"{config.ApiUrl}v1.0/users", result.AccessToken, Display);
}
Now for cross-platform support, I need to develop similar functionality in C++ and for this purpose, we are exploring C++ Rest SDK from Microsoft. But I am unable to find any good examples to achieve a simple thing like providing client ID, client secret to get access token and to authorize.
Please let me know if anyone has come across any example / link to achieve the same.
Here you have some code for oauth 2.0 in Dropbox, Linkedin and MS Live scope:
https://github.com/microsoft/cpprestsdk/blob/master/Release/samples/Oauth2Client/Oauth2Client.cpp
Other samples within C++ Rest SDK:
https://github.com/microsoft/cpprestsdk/tree/master/Release/samples
First of all, you have to distinguish:
1. MS Graph authentication - which is, in fact, Azure Access Directory/Microsoft identity platform authentication, based on oauth 2.0 (short name: MSAL)
2. Accessing the MS Graph API using access token from the authentication process (in the standard process you should use MS Graph SDK)
For the C++ there is no MSAL or SDK library.
So - for authentication, you should use oauth 2.0 example which I pasted above.
Because you need to write everything on your own, please read deeply docs about authentication for MS Graph
https://learn.microsoft.com/en-us/graph/auth/
Here you can watch all the needed endpoints, secrets etc. for sample Postman calls:
https://learn.microsoft.com/en-us/graph/use-postman#set-up-on-behalf-of-api-calls
https://developer.microsoft.com/en-us/graph/blogs/30daysmsgraph-day-13-postman-to-make-microsoft-graph-calls/
In the URLs there are the following variables used:
Callback URL: https://app.getpostman.com/oauth2/callback
Auth URL: https://login.microsoftonline.com/**TENANTID**/oauth2/v2.0/authorize
Access Token URL: https://login.microsoftonline.com/**TENANTID**/oauth2/v2.0/token
Client ID: CLIENTID
Client Secret: CLIENTSECRET
Scope: https://graph.microsoft.com/.default
State: RANDOMSTRING
For the API calls, read about Microsoft Graph REST API v1.0 reference
https://learn.microsoft.com/en-us/graph/api/overview?toc=./ref/toc.json&view=graph-rest-1.0

Postman Script to set Environment variable

I am creating a postman collection for one of API integration with our Service. Here we are using OAuth1.0 for authentication. I want to set the oauth init response oauth_token, oauth_token_secret into postman environment variables so that I can access them in further requests.
The response is in below format not a JSON.
oauth_token=oauth_token_value&oauth_token_secret=oauth_token_secret_value&oauth_callback_confirmed=true
I tried below script:
var output = require('querystring').parse(Response.text);
postman.setGlobalVariable("oauth_token", output.oauth_token);
postman.setGlobalVariable("oauth_token_secret", output.oauth_token_secret);
Can some one help me to set tokens into postman environment variables please.
Note: I am using chrome plugin Version 5.5.4, not native app.
In the chrome extension you need to use postman.setEnvironmentVariable():
postman.setEnvironmentVariable("oauth_token", output.oauth_token);
postman.setEnvironmentVariable("oauth_token_secret", output.oauth_token_secret);
For that you need to have an environment created and selected (no need to add any variable manually). How to do that is described here: https://learning.postman.com/docs/sending-requests/managing-environments/#creating-environments

How to make Django Server URL config-driven instead of being hard-coded?

I am using Django with React, each time I have to use React to get the data from the database I have to do something like this:
var URL = 'http://127.0.0.1:8000/users/api/games/'
var API_URL = URL + '?term=' + this.props.token
await axios.get(API_URL)
.then(res => {
temp = res.data
})
How can I avoid hardcoding "http://127.0.0.1:8000/" like this and set up it in the setting.py? Can someone show me how to do it? Thanks a lot!
If I understand you correctly this only needs to be changed in the React app and not in the settings.py of Django.
Take the URL of wherever you deploy your Django application (in development this could be locally at 127.0.0.1:8000 but in Production this will most likely be something like api.example.com) and this will become an Environment Variable injected at build time of your React app.
Generally you will have a .env configuration file per environment (DEV/TEST/PROD etc.) which will contain all variables that can then be used in your code.
Check out Using environment variables in React for a detailed post on why you would use environment variables and how to use them in your Javascript applications.