Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI command to deploy custom contracts #151

Closed
nguyer opened this issue Feb 28, 2022 · 0 comments · Fixed by #155
Closed

CLI command to deploy custom contracts #151

nguyer opened this issue Feb 28, 2022 · 0 comments · Fixed by #155
Assignees
Labels
enhancement New feature or request

Comments

@nguyer
Copy link
Contributor

nguyer commented Feb 28, 2022

It would be very helpful to developers to have a command to quickly and easily deploy a custom contract to the blockchain used by a local FireFly stack. This command would take a pre-compiled contract in the form of a combined JSON file - typically compiled from solc. Here's an example command someone might use to compile their contract (though the exact command will vary depending on the case):

solc --combined-json abi,bin simple_storage.sol > simple_storage.json

I imagine the FireFLy CLI command to deploy the contract would look something like this:

ff deploy <stack_name> <compiled_contract.json>

We should also have an optional flag to tell the CLI which member should deploy the contract.

Here's an example command of how someone might compile their contract

Probably the easiest way to actually get the contract on-chain today is to use Ethconnect's ability to deploy smart contracts. Here is an example of a POST to the Ethconnect for org_0:

POST http://localhost:5102

{
    "headers": {
        "type": "DeployContract"
    },
    "from": "ADDRESS_OF_SIGNING_ACCOUNT",
    "compiled": "BASE64_ENCODED_BYTECODE",
    "abi": ["FULL_ABI_ARRAY"]
}

There are several things to note here:

  • The compiled field needs to be Base64 encoded. The default output of solc is hex encoded bytecode. This means that we need to first decode the bytecode string (from the compiled JSON file) into raw bytes, then re-encode it as Base64 before sending it to Ethconnect.
  • The abi field needs to be the entire array from the compiled JSON file
  • The from field needs to be the Ethereum address of a signer with an unlocked account. This should be easy to look up in the stack's JSON file as they are all written there.

A couple of thoughts on implementation:

  • The actual code for the implementation should be in the blockchain provider, with a new function on the blockchain provider interface
  • The address of the contract should be displayed on the command line after a successful deployment
  • If an error occurs, the error should be passed back from Ethconnect and displayed on the command line
  • The Fabric blockchain provider can just have these functions stubbed out, and print a message saying it's not supported yet. It would be great to support chaincode deployment later, but we need a separate Issue for that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant