π Welcome to Venin! π
... because it's time we start writing Hedera smart-contract dApps1 frictionless and with ease, without having to deal with the hustle and bustle of Hedera's verbose, underlying services.
This project is an independent, community driven, effort to bring clarity and joy towards developing smart-contract applications on the Hedera network-chain ecosystem.
Having said that, we have been featured on Hedera's blog and, hopefully, will continue to be so as Venin draws closer to a more stable-badge status.
Please keep in mind that, although core features are extensively tested and appear to be working, this is still currently under heavy-active development and, as such, we don't recommend this just yet for production use. The API is also very likely to change before we reach there! We strive to document all the changes, including braking ones, in the appropriate docs section.
We will continue to use it "as is" in production even in this initial stage just because we are really familiar with the library and are quick to solve any issues that we might encounter.
The driveβ
As any good-striving, long-lasting, endeavour, we are using Venin to hopefully fuel everything that we, here at Buidler Labs, build on Hedera. Our Hedera portfolio currently consists of:
- FileCoin-Hedera Grant - a development grant used to put the foundations of MyTaskbar v2, the more decentralized version
- HeadStarter - the first Hedera IDO platform
We're basically eating our own dog food. That way, we can hopefully prove that it's something delicious or, if not, we have a good incentive to make it so. This also makes it a good reason to not have it as a "shot and forget" kind of effort.
We will support this for as long as we're going to build on Hedera and, depending on general community interest, even beyond that.
The gistβ
Suppose you want to upload, execute and print the resulting greet
message for the following contract:
// SPDX-License-Identifier: MIT
// compiler version must be greater than or equal to 0.8.9 and less than 0.9.0
pragma solidity ^0.8.9;
contract HelloWorld {
string public greet = "Hello World!";
}
Here's how you would do it in Venin:
- Venin
- Hedera
import {
Client,
PrivateKey,
ContractCreateTransaction,
FileCreateTransaction,
ContractDeleteTransaction,
ContractCallQuery,
Hbar,
AccountId,
} from "@hashgraph/sdk";
import helloWorld from "./hello_world.json";
const client = Client.forName(process.env.HEDERA_NETWORK).setOperator(
AccountId.fromString(process.env.OPERATOR_ID),
PrivateKey.fromString(process.env.OPERATOR_KEY)
);
const contractByteCode = helloWorld.object;
const fileTransactionResponse = await new FileCreateTransaction()
.setKeys([client.operatorPublicKey])
.setContents(contractByteCode)
.execute(client);
const fileReceipt = await fileTransactionResponse.getReceipt(client);
const fileId = fileReceipt.fileId;
const contractTransactionResponse = await new ContractCreateTransaction()
.setGas(75000)
.setBytecodeFileId(fileId)
.execute(client);
const contractReceipt = await contractTransactionResponse.getReceipt(client);
const contractId = contractReceipt.contractId;
const contractCallResult = await new ContractCallQuery()
.setGas(75000)
.setContractId(contractId)
.setFunction("greet")
.setQueryPayment(new Hbar(1))
.execute(client);
const greet = contractCallResult.getString(0);
console.log(greet);
(click on the "Hedera" tab to find out what would be the equivalent of this snippet written solely using the official Hedera SDK JS library)
Oh, by the way, if you haven't done it already, click Run
on the Venin
tab. See what happens.
It should run the code targeting the unknown
account id on the unknown
network. We strive to keep a working balance on it, but if we can't keep up with the usage, you can also
use your own hedera account instead. Hedera's Portal is the best and easiest way to start in this sense.
Once ready, just edit the above code to use it in your own session like so:
const { session } = await ApiSession.default({
wallet: {
sdk: {
operatorId: <Your operator account id>
operatorKey: <Your operator private key>
}
},
network: {
name: "testnet" / "previewnet" / "customnet"
}
});
Head over to our configuration page for more info on other available options.
log
-ingAs you might have noticed, the above example contains a log
call for which there is no function definition provided. This is intentional and has been provided as a behind-the-scene convenience function replacing the previously-used, console.log
variant and freeing it up to target the good-ol'-fashion browser console that we all love-and-dread.
This tends to make the code a little bit non-portable (aka: you can't copy paste it directly from browser and expect it to work), but this can be easily solved by virtually replacing all log
s with console.log
s.
In both cases, we've left out the error handling part for brevity. Besides that, the Hedera code assumes that the developer has precompiled the contract and that its bytecode is provided to it via the ./hello_world.json
file. Venin does not enforce such an assumption. It takes care of the underlying compilation so that the developer does not have to.
Speaking of that, here's a more self-contained code snippet version that basically does the same thing, but gives even more in-browser control to play around with:
... you get the idea. It's that simple!
Give it a spinβ
If you want to quickly get your hands dirty, we prepared a quick-start demo repo for you to play with. You'll first need to setup an .env
file, but don't worry, there are a few mandatory entries and everything is explained in configuration section.
You can also start from the .env.sample
file which is meant to be a minimal-config template. This also means that not all the config options are directly available there so you might as well cross-reference them with the online config values.
Another option would be to just code in-browser using our playground.
Featuresβ
Venin already is packed with a lot of stuff:
βοΈ Compile a Solidity contract to obtain its Hedera accepted ABI directly from within the library (no external compiler required)
βοΈ Deploy a contract to the network
βοΈ Use a fluent API to interact with deployed, live entities such as contracts
βοΈ Pubsub for contract emitted events
βοΈ Pubsub for transaction receipts
βοΈ Fine grained cost-control
βοΈ Browser bundle-able via a custom made Rollup plugin (webpack pending)
βοΈ Using Hedera File Storage as a place to store generic files and JSONs
βοΈ Create token via the Hedera Token Service (HTS)
βοΈ Create a Hedera account
βοΈ Ready to be plugged into a web3 wallet (aka HIP-338 supported)
βοΈ End to end tested, high coverage (targeting a minimum of 85%) sourcing multiple contracts for the test-base from places such as solidity-by-example and the hedera-sdk-js repo
... with more planned for development:β
π² Better integration of entities across the code-base
π² Pubsub mechanics for Hedera's Consensus Service
π² Other account operations
π² Better error reporting
π² Increase logging support
... AND more.
Contributionsβ
Do you think we missed anything? Want some important feature prioritized? Do you have an idea of something that we might improve? Head over to our issues page and let us know! We want Venin to be a community-lead initiative. This means that any opinion or critic is encouraged (and even welcomed)!
Of course, if you're eager to write it yourself, that's also fine and dandy! Just fork us, add your changes and open a pull request. We'll take it from there ...
Oh! And if you ever feel like talking to us, you can reach us on discord. We're ΓΌber friendly! π¨βπ©βπ§βπ¦
Licenseβ
This work has been published under the MIT License
.
- decentralized applicationβ©