DEV Community

foxgem
foxgem

Posted on • Edited on

1

CFOX: A shell for eth dapp developers

  ______  _______   ______   ___   ___
 /      ||   ____| /  __  \  \  \ /  /
|  ,----'|  |__   |  |  |  |  \  V  /
|  |     |   __|  |  |  |  |   >   <
|  `----.|  |     |  `--'  |  /  .  \
 \______||__|      \______/  /__/ \__\
                             CFox 0.0.4
Enter fullscreen mode Exit fullscreen mode

cfox is a shell for eth dapp developers and provided, current supported commands includes:

  Commands:

    help [command...]                  Provides help for a given command.
    exit                               Exits application.
    \e                                 Export all datas in db.
    \l [options]                       List all datas in db.
    \c [options]                       Change current account or chain.
    \a [options]                       Add a chain, account or token to db.
    \r [options]                       Remove a chain, account or token from db.
    qr [account]                       Generate a QR Code for an account, current account will be used when account is missing.
    balance [options]                  Show a balance.
    send [options] <target> <amount>   Send a amount of token to a target account.
    nft [options] <contract>           Show all tokens owned by current account in the contract.
    transfer <contract> <target> <id>  Transfer a nft to a target account.
    gp                                 Show current gas price, if "baseFeePerGas" is not empty, then fast / standard / low are values of "maxPriorityFeePerGas". Otherwise, they are normal gas prices before EIP1559.
    exec <contract>                    Execute any function in the contract definition.
    query <contract>                   Query any event logs caused by the contract.
    ens <value>                        Execute ENS action, the returned value depends on <value>: an ens name if it is an address; an address when it is an ens name.
    wallets [options]                  Generate n wallets derived from a random wallet, following BIP-44
    upload [options]                   Upload files to IPFS.
    peek [options]                     Show metadata of a contract or a token.
    nonce [account]                    Show current nonce details of an account, current account will be used when account is missing.
    cancel [options]                   Cancel a tx sent by current account by nonce or transaction hash.
    push <txHash>                      Speed up a tx.
    keys [options] [name] [value]      Configure api keys used by cfox, null will be used when no value is provided.
Enter fullscreen mode Exit fullscreen mode

Installation

npm install -g cfox

Initialization

cfox will ask the user to set the password on its first run:

  ______  _______   ______   ___   ___
 /      ||   ____| /  __  \  \  \ /  /
|  ,----'|  |__   |  |  |  |  \  V  /
|  |     |   __|  |  |  |  |   >   <
|  `----.|  |     |  `--'  |  /  .  \
 \______||__|      \______/  /__/ \__\
                             CFox 0.0.4

cfox=#
This is your first time to run cfox, please do some configurations first.
Please set login password: ***
Please confirm the password: ***
cfox=#
Please input password: ***
Login successfully!
Enter fullscreen mode Exit fullscreen mode

After that, since there are no wallets added the prompt will use ? for current wallet:

cfox[?||mainnet]=#
Enter fullscreen mode Exit fullscreen mode

The prompt format: cfox[current_wallet || current_network], both will be used by the provider or signer running the blockchain related command. You can use \c to change them.

Now, it's time to create a wallet for playing. The simplest way is to run \a -a, which will create an random wallet and set it the current wallet because there is no one.

cfox[?||mainnet]=# \a -a
✔ try to create a new account.
cfox[0xBED16Cd70529D459f4A1A44D6Fe0c6B41364a00C||mainnet]=#
Enter fullscreen mode Exit fullscreen mode

The last step of initialization is to set the keys used by cfox. You can find all the external apis supported by running keys -l. Currently, the result:

cfox[0xBED16Cd70529D459f4A1A44D6Fe0c6B41364a00C||mainnet]=#keys -l

| name        | value |
-----------------------
| infura      |       |
| morails     |       |
| nft.storage |       |
Enter fullscreen mode Exit fullscreen mode

Tip:

You can always find the saved data in the home directory of cfox: "${USER_HOME}/.cfox".

For example, it is "~/.cfox" on linux or macos.

Commands

Each command has a detailed description and you can always know it by running help <command> or <command> --help. For example:

cfox[0xBED16Cd70529D459f4A1A44D6Fe0c6B41364a00C||mainnet]=# help qr

  Usage: qr [options] [account]

  Generate a QR Code for an account, current account will be used when account is missing.

  Options:

    --help  output usage information
Enter fullscreen mode Exit fullscreen mode

The commands using the external apis:

  • nft, it will use morails as a fallback for those contracts not implementing IERC721Enumerable.
  • upload, it depends on nft.storage api to fulfill uploading datas to IPFS.

Tips:

  1. All command line arguments will be splitted by space.
  2. When passing arguments to an event query, missing means null.

Example #1: query all Transfer events in an range.

cfox[0xBED16Cd70529D459f4A1A44D6Fe0c6B41364a00C||mumbai]=#query 0x0dc5a5d352e55dbb3d27c462de6b506517b86443
Event Abi: event Transfer(address indexed from, address indexed to, uint256 value)
event args (address,address):
start block (top n blocks if it is negative.): 30037846
end block: 30038856
✔ try to query event Transfer().

...
Enter fullscreen mode Exit fullscreen mode

Example #2: query all Transfer(,to) events in an range.

cfox[0xBED16Cd70529D459f4A1A44D6Fe0c6B41364a00C||mumbai]=# query 0x0dc5a5d352e55dbb3d27c462de6b506517b86443
Event Abi: event Transfer(address indexed from, address indexed to, uint256 value)
event args (address,address):  0x3B057FD4Ba20D2129b1DD5355CEDE95D4E990ab4
start block (top n blocks if it is negative.): 30037846
end block: 30038856
✔ try to query event Transfer(,0x3B057FD4Ba20D2129b1DD5355CEDE95D4E990ab4).

...
Enter fullscreen mode Exit fullscreen mode

Example #3: query all Transfer(from) events in an range.

cfox[0xBED16Cd70529D459f4A1A44D6Fe0c6B41364a00C||mumbai]=# query 0x0dc5a5d352e55dbb3d27c462de6b506517b86443
Event Abi: event Transfer(address indexed from, address indexed to, uint256 value)
event args (address,address): 0x0000000000000000000000000000000000000000
start block (top n blocks if it is negative.): 30037846
end block: 30038856
✔ try to query event Transfer(0x0000000000000000000000000000000000000000).

...
Enter fullscreen mode Exit fullscreen mode

Development

  1. git clone this repository.
  2. npm i to install all the dependencies.
  3. npm start to start the shell.
  4. npm test to test all the testcases.

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more