Hello,i want to create a contract for creating unique address for each users registered on my website,
function registerUser() public {
// Generate a unique address for the user
address userAddress = address(uint160(uint(keccak256(abi.encodePacked(msg.sender, block.timestamp)))));
// Store the user's unique address in the mapping
userAddresses[msg.sender] = userAddress;
}
Is this code correct for that?
Jul 3, 2023, 5:44 AM
You should simply hash the msg.sender and no need to store it
Jul 3, 2023, 6:57 AM
I want each user can deposit the token and withdraw,when they want to deposit use the self unique address and they can deposit with that address on any wallet they have
Jul 3, 2023, 8:11 AM
You're making no sense to me, also those addresses can't be generated out of thin air
You either need to deploy contracts at that specific address,
Or generate EOA
In both cases you need to brute force
You either need to deploy contracts at that specific address,
Or generate EOA
In both cases you need to brute force
Jul 3, 2023, 8:42 AM
you're trying to achieve account abstraction?
smart contract wallet?
a raw way would be to use a nested mapping of address to hash to uint for balances, and manage the smart contract address (this)'s balance so that each address to hash mapping has a defined balance from the total balancs of contract
and make the transfer function accordingly so that when executed it just changes the balance mapping
Jul 3, 2023, 8:48 AM
I want to create an address inside a website when a user registers to which the user can deposit or withdraw tokens, and if she wants to buy something inside the site, the balance of that address will be reduced.
Jul 3, 2023, 8:49 AM
yes that can be done with state management, using the total contract balances as a central treasury of sort
is this right seniors?
oh like a factory for each users storage contract?
Jul 3, 2023, 8:53 AM
Yep similar
Jul 3, 2023, 8:54 AM
Oh ok
Jul 3, 2023, 8:54 AM
No
Jul 3, 2023, 8:55 AM
wakarimashita senpai
Jul 3, 2023, 8:56 AM
You either deploy new contracts for each user, or use centralized EOA
else the addresses won't be unique
else the addresses won't be unique
Jul 3, 2023, 8:57 AM
can randomly generated hashes be same ?how? like chainlink docs boast their true random number oracle how do they do it?
Jul 3, 2023, 9:08 AM
You're speaking gibberish
Jul 3, 2023, 9:17 AM
I am meaning to ask, you said that the hashes cannot be unique like that... can they be unique if generated using chainlink?
Jul 3, 2023, 9:19 AM
And when I said that?
Jul 3, 2023, 9:19 AM
I didn't understand this... end ending part
Jul 3, 2023, 9:20 AM
That's like the basics, have u skipped your lessons?
Jul 3, 2023, 9:22 AM
some parts, yeah
Jul 3, 2023, 9:24 AM
Depends what you hash :)
Evm is a deterministic environment and hashes too, if you hash multiple times the same string you'll get the same results.
That's why on some protocols you want to use a nonce or datetime or something that is incremental/different at each call so the hash generated is unique
That's why on some protocols you want to use a nonce or datetime or something that is incremental/different at each call so the hash generated is unique
Jul 3, 2023, 10:02 AM
yes yes that... but when I was searching google about all the ways of generating truly random hashes all I could find was to use oracles... But couldn't figure out the inner workings of the chainlink contracts
it said even if using nonce the resulting can be pre calculated if values are provided... and since evm is deterministic in nature, how the hell does chainlink achieve that. I mean calling the random number contact for example, does calling getRandomNum cause the chainlink contract to interact with external sources... if so how did they manage to do that so that smart contract request automatically calls from external sources for values??
ah I am not able to explain it
Jul 3, 2023, 10:32 AM
There are some resources about working of chainlink in this article https://blog.pessimistic.io/oracles-entropy-chainlink-vrf-secure-integration-tips-13c27d8fde48
Jul 3, 2023, 10:40 AM
Have u tried reading their docs, it's well written
Jul 3, 2023, 10:40 AM
yes, but it's still english and sometimes some terms are out of my grasp
it's a hard language to master
okay thanks I'll try reading it if it gets to my head
Jul 3, 2023, 10:42 AM
No it's not
Jul 3, 2023, 11:38 AM