Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cpchain-cli

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cpchain-cli

A CLI tool for developing smart contracts on CPChain mainnet

  • 0.0.10
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

CPChain CLI Tools

License: MIT

This tool aim to help developer develop smart contract on CPChain mainnet.

demo

Usage


npm install -g cpchain-cli

cpchain-cli help

cpchain-cli create my-contract

cd my-contract

yarn

# Test contract
npx truffle test

Base Contracts

The CPChain foundation has provided this repo which has many tested base contracts. Developers can use it to develop and test smart contracts.

Deploy on Testnet

Before deploying contract on the mainnet, we suggest developers the smart contracts on Testnet first to secure test. You can get Test CPC coins by the faucet. This faucet drips 100 CPC every 10 seconds. You can register your account in our queue.

Create account

You can use the cpchain-cli create a account directly.


# create a new account
cpchain-cli account new

You can check your keystore in keystore folder. You can execute cpchain-cli account new -h to get detailed parameters.

Deploy

Now, copy your address and access faucet to get test coins. Then build your contract and deploy it on Testnet:


# build contracts
npm run build

# deploy on testnet (Specify your keystore)
cpchain-cli contract deploy --keystore <The path of your keystore>  -c build/contracts/MyContract.json --endpoint https://civilian.testnet.cpchain.io --chainID 41

# if need deploy multiple contracts which writes in migrations, you can use deploy-truffle command
cpchain-cli contract deploy-truffle --keystore <The path of your keystore> --endpoint https://civilian.testnet.cpchain.io --chainID 41 -P <Project Path>

CPChain CLI Configuration

If you thinks the options is too many to input, you can create a file cpchain-cli.toml, then specify options in this file, as below:


[chain]
endpoint="https://civilian.testnet.cpchain.io"
chainID=41

[wallet]
# The path of your keystore file
keystore="keystore/key.json"
# You can specify the password in configuration (Only in DEVELOPMENT and TESTING, this is unsafe)
# password="123456"

[contract]
# built-contract is the path of the built JSON file by truffle
builtContract=""
# After the contract is deployed, you can specify this field when you need to call the contract
contractAddress=""

Then, when you deploy smart contracts, your commands:


cpchain-cli contract deploy -c build/contracts/MyContract.json

Manage Contract by Command-Line

After deploying your contract, you will need to manage it. The cpchain-cli can also support managing deployed contract. Please run as below to get all commands:


cpchain-cli contract -h

If you want to check options, you can use cpcchain-cli contract view -h, for example:


cpchain-cli contract view -c build/contracts/MyContract.json --contract-address <contract address> -m <method name of parameter name>

You can add -c(--built-contract) and --contract-address to the cpchain-cli.toml as above. Then you don't need to pass these two options in command, just run: cpchain-cli contract view -m <method name>.

If you want to call your contract, you can use cpchain-cli contract call -h, for example:


cpchain-cli contract call -c build/contracts/MyContract.json --contract-address <contract address> -m <function name> --amount <amount> -k <keystore file> --endpoint https://civilian.testnet.cpchain.io --chainID 41

Add you can add --amount to specify the amount of CPC.

Deploy on Mainnet

Just replace the endpoint and chainID with:

Develop


npm i

npm link

scripts/run src/index.ts -h

npm run lint

npm run lint:fix

npm run build

# publish
# npm publish

Transfer CPC

You can transfer CPC by this CLI: cpchain-cli -h. Firstly, please create a file named cpchain-cli.toml:


[chain]
endpoint="https://civilian.testnet.cpchain.io"
chainID=41

[wallet]
# The path of your keystore file
keystore="keystore/key.json"
# You can specify the password in configuration (Only in DEVELOPMENT and TESTING, this is unsafe)
# password="123456"


Then, the commands as below:


cpchain-cli transfer -t 0x1fbBacADcD78f3508aa55bd948fE27660E58a0d2 -a 0.9

FAQ

为什么不用 swc 打包

因为当前版本仅支持 commonjs 打包,不支持 ES Modules(官方文档),考虑当需跟上最新的发展,以及很多库已转向 ES Modules,故先弃用 swc 打包方式。

References

Keywords

FAQs

Package last updated on 28 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc