Suppose I'm having a form wherein I'm taking Name, Password and EmailID and I get the values. How will I be able to update/reflect the data in the ethereum blockchain?

In truffle console, it is UserInfo.then(function(instance){return instance.addPeople("Name", "Password", "Email";}) which would essentially update the data.

Is it possible to write a JSX code exactly as this?

  • Storing password in a smart contract won't be a good idea. Everything that is inside a contract is visible to all external observers. Making something private only prevents other contracts from accessing and modifying the information, but it will still be visible to the whole world outside of the blockchain. – Soham Lawar Aug 29 '18 at 9:20

If you have a contract that can accept that information, then this seems possible. I'm just getting comfortable with truffle console myself, but it makes a couple of things easy (things that won't work quite the same in a d'app outside the console).

So, you create your UserInfo contract. You'll need the addPeople function, etc. I'm not going to write that part, but can follow up with an example if needed.

I use testrpc to make this easy to test. The first time I ran testrpc, I saved the mnemonic words it shows in the initial output (see the end of my post). I then saved those words to a text file (using copy/paste), and then restarted testrpc like this

testrpc --mnemonic "$(cat ./mnemonic.txt)"

This gives me the same initial, pre-created addresses each time, which is handy for consistent testing.

Then you do create the directory, do truffle init, write the contract, do truffle compile, make sure the new contract is in the migrations/2_* file, do truffle deploy (or truffle deploy --reset if you are making an update to the contract). SAVE the contract address here. You'll need it.

Now we are up to truffle console and once you are there, your UserInfo contract is already pre-built (apparently truffle is being nice by having these ready for you in console). Here's the steps you need to run it:

let contractAddress = '<paste saved contract address>'
let abi = UserInfo.abi
let userInfo = web3.eth.contract(abi).at(contractAddress)

Now you can operate on userInfo

userInfo.getEmail() // say this getter method exists in your contract
userInfo.addPeople('Name', 'name@email.com', 'password123', {from: web3.eth.accounts[0]}); // I am new enough I haven't understood a geth-like 'default account' in truffle console

That last 'from' json object is to supply some gas for the transaction, since that one surely alters the state of the contract (adding a person to a mapping, probably).

That's all from the top of my head as I wait on a meeting. It's just the steps, and I was working this stuff out last night so it should be accurate. Let me know if you have problems and I'll see if I can help, too.

(Here's what the last few lines of testrpc look like if you run without --mnemonic)

HD Wallet
Mnemonic:      **analyst hello accuse shoulder able noise surface inform milk walnut remind yard**
Base HD Path:  m/44'/60'/0'/0/{account_index}

Listening on localhost:8545

Copy the bolded list of works starting at analyst and ending at yard.

  • Hans, I appreciate the time you had spent in writing this and it did solve my problem. Even though I had set up the truffle and was quite used to the console, I was kinda not so good with the UI integration part and this did help me :). – Gokul Krishna Jun 21 '17 at 4:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.