Giter Club home page Giter Club logo

rcoin's Introduction

RCoin

This is just a simple example of a coin-like contract. It is not standards compatible and cannot talk to other coin/token contracts. If you want to create a standards-compliant token, check ConsenSys/Tokens.

Starting point

Important files:

  • contracts/RCoin.sol is a smart contract (written in Solidity) that creates a RCoin token.
  • contracts/Migrations.sol file manages and updates the status of your deployed smart contract. This file comes with every Truffle project, and is usually not edited.
  • truffle.js is the Truffle configuration file, for setting network information and other project-related settings. The file is blank, but this is okay, as we will be using a Truffle command that has some defaults built-in.
  • test/TestRcoin.sol  is a test file written in Solidity which ensures that your contract is working as expected.
  • test/rcoin.js is a test file written in JavaScript which performs a similar function to the Solidity test above.

Running the solidity test: truffle test ./test/TestRCoin.sol

Running the JavaScript test: truffle test ./test/RCoin.js

Compiling the smart contracts: truffle compile

Migrating:

  • Migrating with Truffle Develop: To deploy our smart contracts, we're going to need to connect to a blockchain. Truffle has a built-in personal blockchain that can be used for testing. This blockchain is local to your system and does not interact with the main Ethereum network. You can create this blockchain and interact with it using truffle develop then, on truffle develop prompt type migrate. The output will show the transaction IDs and addresses of your deployed contracts.

  • Migrating with Ganache, a desktop application, to launch your personal blockchain.

Edit truffle.js content to the following to allow a connection using Ganache's default connection parameters.

from

module.exports = {
  // See <http://truffleframework.com/docs/advanced/configuration>
  // to customize your Truffle configuration!
};

to

module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",
      port: 7545,
      network_id: "*"
    }
  }
};

Then launch Ganache (...)

To interact with the contract, you can use the Truffle console. The Truffle console is similar to Truffle Develop, except it connects to an existing blockchain (in this case, the one generated by Ganache).

On the terminal, migrate the contract to the blockchain created by Ganache: truffle migrate. Ganache has to run.

truffle console

Example of commands:

RCoin.deployed().then(function(instance){return instance.getBalance(web3.eth.accounts[0]);}).then(function(value){return value.toNumber()});
RCoin.deployed().then(function(instance){return instance.getBalanceInEth(web3.eth.accounts[0]);}).then(function(value){return value.toNumber()});
RCoin.deployed().then(function(instance){return instance.sendCoin(web3.eth.accounts[1], 500);});
RCoin.deployed().then(function(instance){return instance.getBalance(web3.eth.accounts[1]);}).then(function(value){return value.toNumber()});
RCoin.deployed().then(function(instance){return instance.getBalance(web3.eth.accounts[0]);}).then(function(value){return value.toNumber()});

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.