How can I deploy a smart contract to RSK without using Truffle? - rpc

After compiling a Solidity file using solc, how can I deploy the output bytecode as a smart contract to RSK?
I know how to do this using Truffle already, but what alternatives are there available for this task?

RSK is (mostly) compatible with Ethereum.
In particular, for dev tools,
it has JSON-RPC compatibility plus VM compatibility.
So if you are a Ethereum developer,
you can use tools/ libs that you are familiar with.
Here are several methods, apart from Truffle:
using Geth console and Remix, or
using Metamask/Nifty and Remix, or
using MyCrypto or MyEtherWallet
contract deploy tools (if you have the contract bytecode).
If you want to do this manually,
you can do so using the terminal by
sending a transaction using curl
via JSON-RPC like this:
curl \
-X POST \
-H "Content-Type:application/json" \
--data '{"jsonrpc":"2.0","method":"eth_sendTransaction","params":[{"from":"FROM_ADDRESS","to":"0x00","gasPrice":"0x3938700","gas":"0x67C28", "data":"SIGNED_CONTRACT_DEPLOYMENT_BYTECODE"}],"id":1}' \
http://localhost:4444
Use the eth_estimateGas RPC to obtain the value of gas.
Use the eth_gasPrice RPC to obtain the value of gasPrice.
Note that the above command assumes that you have RSKj running on localhost.
Also note that just like any other transaction
which modifies the state of the blockchain,
you will need to sign the deployment transaction as well,
in order to produce SIGNED_CONTRACT_DEPLOYMENT_BYTECODE.
You can use the eth_sign RPC for this,
or the equivalent method in your wallet.

Yes, it is good to know what happen in these situations. Short answer: you send a transaction, to field is empty, data field containts the bytecode of the compiled contract CONCATENATED with the ABI encoded arguments for constructor, if any
Usually, I write my own utilities (in NodeJS, to be cross platform), to interact with an Ethereum/RSK node. You can explore the code of the implemention of client.deploy in my personal project https://github.com/ajlopez/rskapi
Also, you can check the implementation of my command line tools (based on the above library) https://github.com/ajlopez/rskclitools#deploy-a-contract
An code example in https://github.com/ajlopez/EthFaucet/tree/master/commands (see execute setup)
I will add the feature to provide directly the bytecode to deploy command, and in a few days, I will write a post with a bit more organized description

Related

What is the difference between fabric-chaincode-go and fabric-contract-api-go?

I am currently trying to learn Hyperledger Fabric , I managed to understand how to setup the network (Orderers, Peers, etc.) but now comes the part of the chaincode.
But, I found two different git repos for (what I understand) can be used to create chaincodes.
The first One being the fabric-contract-api-go, I followed their tutorials a while ago.
And the second one being the fabric-chaincode-go.
So my question is, what is the difference between these two packages, and which one should I use for writing chaincodes? Do you have resources or good examples? (other than the ones in the fabric-samples git)
I followed the fabric-contract-api tutorial and wrote a chaincode a while ago, but now I see people using the fabric-chaincode-go package, and I am a bit lost.
I am sorry, this question might sound stupid, but I don't have a Developer background. I have a SysAdmin background, and not used to GOLANG (but I am a fast learner, given to good resources).
You can think of fabric-contract-api-go as a high-level api that builds on/requires the low-level api fabric-chaincode-go.
It's possible to write golang chaincode using only the low-level api - in fact, this was the only option before Fabric 2.0, when the contract api was also added for golang. Previously, it only existed for node and java chaincode.
If you have the option to use the contract api, doing so will e.g. save you some boiler plate code.
To see the difference, you can e.g. compare the fabcar example: in the 1.4 branch, it used the low-level api (shim). In the master branch however it uses the new contract-api.

Connect new peer to existing Hyperledger form client side

I just setup a hyperledger network in single local system. I Already done to add new Org to an existing network using the tutorial here . I need to know something that
Q. Is possible to use hyperledger to add new peers(or run new peers) from client side..??
The short answer is yes, it is possible.
It has been done already, for example IBM has a full Hyperledger offering where everything is configurable via APIs. You can create channels, orgs, peers, join them etc, anything you need to build and manage a network is there.
What you could do is to build an API, which is capable of executing scripts on the machine(s) where your network is deployed. You could build such API in a language of your choosing, secured in some way and you could offer a few endpoint which do what you need to do.
First step in doing this is creating the script(s) which can do what you need. Make sure you have a repeatable process, write down all the commands you need, from the URL you already visited, step by step, until you go from nothing to the simplest version of the network you're happy with.
Create a script with all the commands you've already tested. Make sure the script can take the parameters it needs so they can be later passed via the API, like channel name, org name whatever your script creates basically.
Create an API with an endpoint which can called, has the required permissions and runs in the right location and can execute the script you just created. Make sure you pass the parameters you need from the API endpoint, to the script.
Now you can call the API from the client side.
Things to consider, the API needs to be secured somehow.
So, Yes it is possible and No, it is not an easy job.
Is it worth doing it? Only you can answer that question to be honest.
You would also need to keep up with the changes introduced by each version increment so that's even more work to consider.

How to use Telegram's TDlib with Node.js

There is TDlib which allows to work with Telegram Client API.
Documentation says that it's possible to use it with almost any language.
I can't imagine myself how I can use it with Node.js
Could you tell me where to start from or provide me with a sample code?
You can make requests and get updates using td_json_client and node-ffi interfaces. Official repository provides a simple example.
If you don't want to create API client from zero, you may use one of exists. For example, check out Airgram. This is a strong typed tdlib client for NodeJS.
You can probably port one of the examples on their GitHub repos (Python can be an easy one). You needs to learn how to use binary modules with node.
Or you can check one of the 3rd party libraries (eg. https://github.com/k-egor-smirnov/node-tg-native)
There are 2 active TDLib wrappers in Node.js:
https://github.com/airgram/airgram
https://github.com/Bannerets/tdl
Both require you to build the TDLib binary yourself before using these wrapper: https://tdlib.github.io/td/build.html

Do we really need to import Corda's code for RPC ? How in the future?

I know that Corda is in the process of removing its web server module and in the documentation they suggest the use of other frameworks.
In one example ("spring-observable-stream") they use Spring Boot for the server-side APIs and use an RPC call to the actual running Corda node. That's fine and comparable with what I have to do.
In that example, the author import the specific Corda's RPC code, along with the code of the actual flow (and states) needed.
What I want to ask here is if it's possible to avoid that tangle and keep the web server APIs independent from the actual Corda/CordApp's code by using a general RPC library (any advice ?).
If, instead, I must import the Corda-specific code (there is a reason ?), I'd like to ask you:
What is the minimum necessary to do so from a Gradle perspective ?
Is it possible to implement some sort of plugin on the CordApp to reduce that tangle ?
To be honest, I'm interested in a more general way for interacting with the CordApp (e.g. from Python), but I know that due to the AMQP integration not yet ready, we have to stay on the JVM for now. So, feel free to answer just about what we need to do as of today from Kotlin (which I have to use for a short-term PoC)…
Thank you in advance!
Currently, your server has to depend on the Corda RPC library to interact with nodes via RPC. Corda doesn't yet expose an independent format for sending and receiving messages via RPC.
Your server also needs to depend on any CorDapps that contain flows that the server will start via RPC, or that contain types that will be returned via RPC. Otherwise, your server will not be able to start the flows or deserialise the returned types.
If you're using Gradle, here's what a minimal dependencies block might look like:
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
cordaCompile "net.corda:corda-rpc:$corda_release_version"
compile "com.github.corda:cordapp-example:release-V1-SNAPSHOT"
}
Here, we're depending on the corda-rpc library, and also using JitPack to depend on the CorDapp where we define the flows and states that we want to start/return via RPC.
If you want, you can modularise the CorDapp so that all the classes you need to depend on for RPC are included in a separate module, and only depend on that module.

REST API with versioned data and differential endpoint : optimizing bandwidth and performance

My NodeJS project is based on SailsJS, itself using ExpressJS.
Its API will be used by mobile apps to fetch their data from it.
The tricky part is I don't want the client apps to fetch the whole data tree every time there is a change in the database.
The client only needs to download a differential between the data it's already got and the data on the server.
To achieve that I thought of using git on the server. That is create a repository and save all endpoints as a json file in the repo. Each save will trigger an automatic commit.
Then I could create a specific API endpoint that will accept a commit sha as a parameter and return a diff between that and git HEAD.
This post by William Benton comforted me with this idea.
I'm now looking for any tips that could help me get this working based on the language and frameworks cited above :
I'd like to see a proof of concept of this in action but couldn't find one
I couldn't find an easy way to use git with NodeJS yet.
I'm not sure how to parse the returned diff on client apps developed with the IONIC framework, so AngularJS.
Note : The api will only be readable. All DB movement will be triggered by a custom web back-end used by few users.
I used the ideas in that post for an experimental configuration-management service. That code is in Erlang and I can't offer Node-specific suggestions, but I have some general advice.
Calling out to git itself wasn't a great option at the time from any of the languages I was interested in using. Using git as a generic versioned-object store actually works surprisingly well, but using git plumbing commands is a pain (and slow, due to all of the forking) and there were (again, at the time) limitations to all of the available native git libraries.
I wound up implementing my own persistent trie data structure and put a git-like library interface atop it. The nice thing about doing this is that your diffs can be sensitive to the data format you're storing; if you call out to git, you're stuck with finding a serialization format for your data that is amenable to standard diffs. (Without a diffable format, though, you can still send back a sequence of operations to the client to replay on whatever stale objects they have.)

Resources