Can't lookup ENS name on testnet of an address - blockchain

I'm trying to create an app that works with ENS. I tried registering a test domain on Georli network. Here's the link when I lookup that test domain on app.ens.domains.
https://app.ens.domains/name/rikikudo6.test/details
I try using ethers to resolve ens domain as well as looking up a specific address. Here's the code I'm using:
var ethers = require("ethers");
// I use rpc endpoint generated by alchemy on Georli network
var provider = new ethers.providers.JsonRpcProvider(rpc);
(async () => {
var address = await provider.resolveName("rikikudo6.test");
console.log("address :>> ", address);
const ens = await provider.lookupAddress(address);
console.log("ens :>> ", ens);
})();
And here's the result when I run the above script:
address :>> 0x8A2D9D8e54FF47d28Cc35Aa2ba244d49F14944cA
ens :>> null
I don't understand why it can resolve the name for rikikudo6.test but can't lookup ens for the address returned by the resolving function. Am I missing anything?

I found the answer myself. The lookupAddress only returns the ENS name which is set to the default ENS name of user. If the user doesn't have the default ENS name, it will return null.

Related

How to correctly set up a WebSocketProvider in ethers.js?

I'm trying to switch my dapp from Web3Provider to WebSocketProvider,
form this:
const provider = new ethers.providers.Web3Provider(window.ethereum)
const accounts = await window.ethereum.request({ method: "eth_accounts" })
const account = accounts[0]
const signer = provider.getSigner()
to this:
const provider = new ethers.providers.WebSocketProvider("ws://localhost:8545") <-
const accounts = await window.ethereum.request({ method: "eth_accounts" })
const account = accounts[0]
const signer = provider.getSigner()
With this change I can interact with the Contract only with account that creates and deploy the smart contract, also, the transactions have no confirmation from the user. However, when I try to call some Contract function with another address I get this error:
On the fourth line, the value of the "from" key is different from the address actually selected in the metamask, in fact it is the address of the creator of the Smart Contract. There seems to be some problem with the signer or what? With Web3Provider everything works fine.
Can you help me in any way or tell me more about WebSocketProvider?
Thanks in advance

How to get TRC20 transactions to an address

I am using tron web to query transactions of an address but it does not return transactions sent to that address where token transferred is TRC20.
This does not work.
I want to get the transactions on an address and get both TRX, trc10 and trc20 transactions.
What am I doing wrong or how to do that?
Here is my code block:
tronWeb.setDefaultBlock("latest");
var result = await tronGrid.account.getTransactions(address, {
only_confirmed: true,
only_to: true,
limit: 10
});
console.log(JSON.stringify(result));
})();
After a lot of research, I found out one can easily query contract events at intervals to get transactions on that contract address and you can then filter it for the address you are watching since you can't get a webhook or websocket with your trongrid/tronweb implementation.
Here is a sample file I used to achieve this and it works great for monitoring many address even with different contract addresses.
Note: In my own implementation, this node file is called from another file and other logistics are handled in the other file, but below you see how I queried the transfer events emitted by the specified contract
const TronWeb = require("tronweb");
const TronGrid = require("trongrid");
const tronWeb = new TronWeb({
fullHost: "https://api.trongrid.io"
});
const tronGrid = new TronGrid(tronWeb);
const argv = require("minimist")(process.argv.slice(2));
var contractAddress = argv.address;
var min_timestamp = Number(argv.last_timestamp) + 1; //this is stored for the last time i ran the query
(async function() {
tronWeb.setDefaultBlock("latest");
tronWeb.setAddress("ANY TRON ADDRESS"); // maybe being the one making the query not necessarily the addresses for which you need the transactions
var result = await tronGrid.contract.getEvents(contractAddress, {
only_confirmed: true,
event_name: "Transfer",
limit: 100,
min_timestamp: min_timestamp,
order_by: "timestamp,asc"
});
result.data = result.data.map(tx => {
tx.result.to_address = tronWeb.address.fromHex(tx.result.to); // this makes it easy for me to check the address at the other end
return tx;
});
console.log(JSON.stringify(result));
})();
You are free to customize the config data passed to the tronGrid.contract.getEvents method. Depending on how frequently transactions come on the contract you are monitoring you should DYOR to know at what interval is great for you and what limit value you should pass.
Refer to https://developers.tron.network/docs/trongridjs for details.
I found a API that can take TRC20 transactions, but I haven't found an implementation in webtron.
https://api.shasta.trongrid.io/v1/accounts/address/transactions
Related document:
https://developers.tron.network/reference#transaction-information-by-account-address

web3.eth.getAccounts() returns empty array when using Infura provider. Why?

I was trying to use Infura api to make an Ethereum web app. First I compiled a solidity contract and then deployed it using infura api on rinkeby network. Here is my deploy script which seems to be running successfully.
const HDWalletProvider = require("truffle-hdwallet-provider");
const Web3 = require('Web3');
const compileFactory = require('./build/CampaignFactory.json');
const provider = new HDWalletProvider(
"MY_SECRET_MNEMONIC",
"https://rinkeby.infura.io/v3/363ea9633bcb40bc8a857d908ee27094"
);
const web3 = new Web3(provider);
console.log("provider info: " + provider);
const deploy = async () => {
const accounts = await web3.eth.getAccounts();
console.log("account used: " + accounts[0]);
result = await new web3.eth.Contract(JSON.parse(compileFactory.interface))
.deploy({data: "0x"+compileFactory.bytecode})
.send({from: accounts[0]});
console.log("deployed to address: " + result.options.address);
};
deploy();
Then I created another script web3.js which creates a web3 provider using Infura api:
import Web3 from 'web3';
let web3;
if (typeof window !== 'undefined' && typeof window.web3!=='undefined') {
// we are in the browser and metamask is running.
web3 = new Web3(window.web3.currentProvider);
console.log("using metamask");
}
else {
// we are in server OR user without metamask.
const provider = new Web3.providers.HttpProvider(
"https://rinkeby.infura.io/v3/363ea9633bcb40bc8a857d908ee27094"
);
web3 = new Web3(provider);
console.log("using infura");
}
export default web3;
but when I import this web3.js file somewhere and then try to use 'web3' object, it returns empty array of accounts. For example:
import web3 from '../../ethereum/web3';
...
const accounts = await web3.eth.getAccounts();
console.log("Account list: "+accounts); // returns empty array.
But ideally it should return the accounts list associated with my mnemonic. What is the problem?
A naive solution is to use the HDWalletProvider in your second script, instead of the HttpProvider.
What exactly do you want to do with the second script? I suspect that the second script is something that you want to deploy with a DApp, so including your mnemonic there is a good way to give away all your ether to the first user who knows how to "view source".
If so, in the first script, display the addresses associated with your mnemonic using: provider.getAddresses() and then hard-code those addresses into the second script, for later usage. Naturally, you won't be able to sign any transactions in the second script, but at least you can read data associated with those addresses.
Put await window.ethereum.enable() before web3.eth.getAccounts(),
Or use requestAccounts() instead of getAccounts() :
await web3.eth.requestAccounts();

Resolve ISitecoreService using SimpleInjector

ISitecoreService accepts database name as a string parameter in its constructor (web or master)
ISitecoreService service = new SitecoreService("master"); //or
ISitecoreService service = new SitecoreService("web");
Is it possible I dynamically send database name as parameter to IoC and resolve it? for example I send web/master string parameter and get a new instance of ISitecoreService
Like this?
container.Register<ISitecoreService>(() => new SitecoreService("master"));
Expanding on Stevens answer as I have experience with Sitecore and I love Simpleinjector.
If you like you can get at the Sitecore configuration when your application is bootstrapping using the configuration factory, access the website site configuration and use the database property.
var sites = Sitecore.Configuration.Factory.GetSiteInfoList();
var website = sites.Single(s => s.Name == "website");
ISitecoreService service = new SitecoreService(website.Database);
container.Register<ISitecoreService>(() => service);
This way your SitecoreService will be newed up with the same database that is defined in the website configuration.

How to get city name and Remote IP address from Geocoder gem?

Rails 4 + Ruby 2 + Geocoder gem
Controller Action
def index
#your_id = request.ip #here i am getting localhost IP address like "127.0.0.1"
binding.pry
end
I think in #your_id , it should capture IP address not localhost IP address("127.0.0.1").
But at view i need to show the city that depends on my location example if you are in NY city then it should show NY city (by ip address) dynamically.
Any idea how to get city_name and IP address?
The geocoder gem provides a #location method on the request object (source) which returns a location result with latitude and longitude:
request.location
=> #<Geocoder::Result::Freegeoip:0x007f8ecca5d608
#cache_hit=true, #data= {
"ip"=>"199.21.87.210", "country_code"=>"US",
"country_name"=>"United States", "region_code"=>"CA", "region_name"=>"California", "city"=>"Berkeley", "zipcode"=>"", "latitude"=>37.8716, "longitude"=>-122.2728, "metro_code"=>"807", "areacode"=>"510"
}>
To test this functionality in the browser, try using ngrok to expose your local server and throw some debugger statements in your controller to see what the request.location object looks like.