Coder Social home page Coder Social logo

hyc0812 / simple-storage-truffle Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 26 KB

Simple Tutorial explaining how to deploy and interact with smart contract using truffle

License: Apache License 2.0

Solidity 11.56% JavaScript 88.44%
truffle blockchain simplestorage tutorial

simple-storage-truffle's Introduction

Interact with blockchain and smart contract using truffle

Simple Tutorial explaining how to deploy and interact with smart contract using truffle

Run the code:

Spawn a development blockchain locally:

$ truffle develop

It will automatically start a truffle(develop) CLI.

Deploy the smart contract to the development blockchain:

> migrate --reset

Update data:

> let storage = await SimpleStorage.deployed()
> let data = await storage.updateData(10)

Might get message:

✓ Transaction submitted successfully. Hash: 0x3f6f0e5d0ceca3d0a3ecedf35a1b1ca54873e477f94bf9dedd79e8544dcc5293

Read data:

> let read = await storage.readData()
> read.toString()

Get message: '10'

Useful truffle commands:

To list all the accounts' address:

> let accounts = await web3.eth.getAccounts()
> accounts

'0x722CD3807110b915f97Ef732fa50d9c7Dd024f45',

'0x20f3a0D05b6D28e09259328184a126a28C48ec6d',

.....

find out a account address:

> accounts[0]

'0x722CD3807110b915f97Ef732fa50d9c7Dd024f45'

Create contract instance using specific account with a instance name:

> let myContract2 = await SimpleStorage.new("ss123", {from: accounts[9]})

✓ Transaction submitted successfully. Hash: 0x61e68f5097fdbb6b9f3d20c5509dc391ac1badefb04ff88c43c63730080e898a

Set the data:

> let update = await myContract2.updateData(33)

✓ Transaction submitted successfully. Hash: 0xa9de6b6e76f34227250e4ebfeb59617bd6e8de5e901dc3b42628f09219115123

Read data from another account:

> let read = await myContract2.readData({from: accounts[1]})
> read.toString()

'33'

Or read:

> (await myContract2.readData({from: accounts[1]})).toString()

simple-storage-truffle's People

Contributors

hyc0812 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.