0.1.7 • Published 4 years ago

@newos/cli v0.1.7

Weekly downloads
1
License
GPLv3
Repository
github
Last release
4 years ago

NewOS Command-Line Interface (@newos/cli)

Command-line interface for NewOS.

NewOS is a platform to develop, deploy and operate smart contract projects on NewChain and every other EVM and eWASM-powered blockchain.

Install

First, install Node.js and npm. Then, install the NewOS running:

npm install --global @newos/cli

Usage

To start, create a directory for the project and access it:

mkdir my-project
cd my-project

Use npm to create a package.json file:

npm init

And initialize the NewOS project:

newos init my-project

Create file Counter.sol in directory contracts:

// contracts/Counter.sol
pragma solidity ^0.5.0;

contract Counter {
	uint256 public value;

    function increase() public {
       value++;
     }
 }

Uncomment the testnet section in networks.js and fill your mnemonic on newchain testnet:

const HDWalletProvider = require("newtruffle-hdwallet-provider");

module.exports = {
  networks: {
  	...
    testnet: {
      provider: function() { 
        return new HDWalletProvider("[Your mnemonic]", 'https://rpc1.newchain.newtonproject.org', "testnet") 
      },
      network_id: "1007"
    },
    ...

Deloy upgradeable contract to testnet:

$ newos deploy
✓ Compiled contracts with solc 0.5.17 (commit.d19bba13)
? Choose the kind of deployment upgradeable
? Pick a network testnet
? Pick a contract to deploy Counter
✓ Compiled contracts with solc 0.5.17 (commit.d19bba13)
✓ Contract CounterUpgradeable deployed
All implementations have been deployed
✓ Setting everything up to create contract instances
✓ Instance created at 0x63Be78c0174A87Eadd50BffFD765889C07a38EA4
To upgrade this instance run 'newos upgrade'
0x63Be78c0174A87Eadd50BffFD765889C07a38EA4

Execute the contract method:

$ newos send-tx
? Pick a network testnet
? Pick an instance Counter at 0x63Be78c0174A87Eadd50BffFD765889C07a38EA4
? Select which function increase()
✓ Transaction successful. Transaction hash: 0x7c4bbb1580f810017d0d2d158034ba3b38ae1cd053913bc3cec269c01b9e378c

Retrieve the variable value:

$ newos call
? Pick a network testnet
? Pick an instance Counter at 0x63Be78c0174A87Eadd50BffFD765889C07a38EA4
? Select which function value()
✓ Method 'value()' returned: 1
1

Change the contract Counter.sol to:

// contracts/Counter.sol
pragma solidity ^0.5.0;

contract Counter {
  uint256 public value;

  function increase(uint256 amount) public {
    value += amount;
  }
}

Upgrade the Counter contract:

$ newos upgrade
? Pick a network testnet
? Which instances would you like to upgrade? Choose by name
? Pick an instance to upgrade Counter
? Call a function on the instance after upgrading it? No
✓ Compiled contracts with solc 0.5.17 (commit.d19bba13)
✓ Compiled contracts with solc 0.5.17 (commit.d19bba13)
✓ Contract CounterUpgradeable deployed
All implementations have been deployed
✓ Instance upgraded at 0x63Be78c0174A87Eadd50BffFD765889C07a38EA4. Transaction receipt: 0x7af93f8388bf1d08b36be915116d4f2aa8ff751ec0af6fce0363eba83ebf22f2
✓ Instance at 0x63Be78c0174A87Eadd50BffFD765889C07a38EA4 upgraded

Execute the new method of upgraded contract:

$ newos send-tx
? Pick a network testnet
? Pick an instance Counter at 0x63Be78c0174A87Eadd50BffFD765889C07a38EA4
? Select which function increase(amount: uint256)
? amount: uint256: 10
⠋ Calling: 'increase' with:
✓ Transaction successful. Transaction hash: 0x50179c575116ddd64fa56733818587d38cc6a892aa54cf8ca1a6507f6d128939

Retrieve the same variable value and verify whether the upgrade is success:

$ newos call
? Pick a network testnet
? Pick an instance Counter at 0x63Be78c0174A87Eadd50BffFD765889C07a38EA4
? Select which function value()
✓ Method 'value()' returned: 11
11

License

GPLv3