Go implementation of the C3 protocol
- Docker
- IPFS
- Patchutils
- MacOS
brew install patchutils
- Linux
[sudo] apt-get install patchutils
- MacOS
Set up a localhost proxy route to 123.123.123.123
$ sudo ifconfig $(ifconfig | grep LOOPBACK | awk '{print $1}' | sed -E 's/[^a-zA-Z0-9]+//g') 123.123.123.123/24
Then configure daemon.json
to include the private registry as insecured (because it's localhost).
{
"insecure-registries" : [
"123.123.123.123:5000"
]
}
- Linux
/etc/docker/daemon.json
- macOS
~/.docker/daemon.json
Restart the docker daemon after configuring daemon.json
Install using go get
(must have Go installed).
$ go get -u github.com/c3systems/c3
Warning: Tutorial is not the most intuitive. Please bear with me as we're still in the proof-of-concept stage.
- Generate new private keys
$ c3-go generate key -o priv.pem
$ c3-go generate key -o priv2.pem
- Run the C3 node
$ c3-go node start --pem=priv.pem --uri /ip4/0.0.0.0/tcp/3330 --data-dir ~/.c3
INFO[0002] [node] 0: /ip4/127.0.0.1/tcp/3330/ipfs/QmNRR7uLZ2bZXjjQqEY5fcm5BXubBEne3bkq6pYwg1QR18
source="start.go:152:node.Start"
- In another terminal, clone and build the hello-world dapp
$ git clone https://github.com/c3systems/c3-sdk-go-example-hello-world.git hello-world
$ (cd hello-world && docker build .)
- Push the image to IPFS
$ c3-go push $(docker images -q | grep -m1 "")
[registry] uploaded to /ipfs/QmWJF5MYtnjb76P1CXQsn8MHpT26tjdBcs6CzKfR7zjRBm
source="registry.go:101:registry.(*Registry).PushImage"
- Deploy the image to the local C3 testnet (update
image
andpeer
to your own values)
$ c3-go deploy --priv priv2.pem --genesis '' --image QmWJF5MYtnjb76P1CXQsn8MHpT26tjdBcs6CzKfR7zjRBm --peer "/ip4/127.0.0.1/tcp/3330/ipfs/QmZQ3cJMMjA7HUyEvsMXmN73LZ7fKsrQUmyKwsxrpecb7Z"
- The private key is the second key derived from step 1.
- The peer multihash was derived from step 2.
- The image hash was derived from step 4.
- Invoke a method on the dApp (update
image
andpeer
to your own values from the previous step)
$ go run main.go invokeMethod --priv priv2.pem --payload '["setItem", "foo", "bar"]' --image QmWJF5MYtnjb76P1CXQsn8MHpT26tjdBcs6CzKfR7zjRBm --peer "/ip4/127.0.0.1/tcp/3330/ipfs/QmZQ3cJMMjA7HUyEvsMXmN73LZ7fKsrQUmyKwsxrpecb7Z"
-
In this example we're invoking the
setItem
method which accepts two arguments; the values arefoo
andbar
. The example dApp code is found here. -
The private key is the second key derived from step 1.
-
The peer multihash was derived from step 2.
-
The image hash was derived from step 4.
- That's it; you've just deployed a dApp and invoked a method by broadcasting a transaction.
Show help for C3
$ c3-go help
$ c3-go push {imageID}
$ c3-go pull {ipfsHash}
$ c3-go node start [options]
$ c3-go generate key
$ c3-go encode [options]
$ c3-go deploy [options]
$ c3-go invokeMethod [options]
$ c3-go sign --priv=priv.pem --image={imageID} --payload='["someMethod", "foo", "bar"]'
$ make test
Tests require docker daemon and IPFS daemon to be running.
Install new dependencies to vendor/
(will take a couple of minutes)
$ make deps