Kadena.ex
Kadena.ex is an open source library for Elixir that allows developers to interact with the Kadena Chainweb.
What can you do with Kadena.ex?
- Construct commands for transactions.
- Implement cryptography required by the network.
- Interacting with public network endpoints:
- listen, local, poll, send, spv, cut.
- Send, test and update smart contracts on the network.
Installation
Add kadena to your list of dependencies in mix.exs:
def deps do
[
{:kadena, "~> 0.8.0"}
]
end
Roadmap
The latest updated branch to target a PR is v0.9
You can see a big picture of the roadmap here: ROADMAP
What we're working on now 🎉
Done - What we've already developed! 🚀
Click to expand!
Building Commands
This library allows to build command payloads in a composable and semantic manner. These commands are intended to be used as the request body to the Pact API endpoints.
There are two type of commands:
ExecutionContinuation.
Execution Command
To create an execution command is needed:
The following example shows how to create an execution command:
Kadena.Pact.ExecCommand.new()
|> Kadena.Pact.ExecCommand.set_network(network_id)
|> Kadena.Pact.ExecCommand.set_code(code)
|> Kadena.Pact.ExecCommand.set_nonce(nonce)
|> Kadena.Pact.ExecCommand.set_data(env_data)
|> Kadena.Pact.ExecCommand.set_metadata(keypair)
|> Kadena.Pact.ExecCommand.add_keypair(keypair)
|> Kadena.Pact.ExecCommand.add_signers(signers_list)
|> Kadena.Pact.ExecCommand.build()
NetworkID
There are three options allowed to set a NetworkID:
:testnet04:mainnet01:development
Code
String value that represents the Pact code to execute in the Execution Command.
Nonce
String value to ensure unique hash. You can use current timestamp.
EnvData
A map must be provided to create an environment data, for example:
data = %{
accounts_admin_keyset: [
"ba54b224d1924dd98403f5c751abdd10de6cd81b0121800bf7bdbdcfaec7388d"
]
}
Kadena.Types.EnvData.new(data)
MetaData
To create a MetaData:
raw_metadata = [
creation_time: 0,
ttl: 0,
gas_limit: 2500,
gas_price: 1.0e-2,
sender: "account_name",
chain_id: "0"
]
Kadena.Types.MetaData.new(raw_metadata)
KeyPairs
There are two ways to get a keypair:
# generate a random keypair
{:ok, %Kadena.Types.KeyPair{} = keypair} = Kadena.Cryptography.KeyPair.generate()
# derive a keypair from a secret key
secret_key = "secret_key_value"
{:ok, %Kadena.Types.KeyPair{} = keypair} = Kadena.Cryptography.KeyPair.from_secret_key(secret_key)
KeyPairs with Capabilites
Creating a keypair with capabilities:
clist =
Kadena.Types.CapsList.new([
[name: "gas", args: ["COIN.gas", 0.02]],
[name: "transfer", args: ["COIN.transfer", "key_1", 50, "key_2"]]
])
keypair_values = [
pub_key: "pub_key_value",
secret_key: "secret_key_value",
clist: clist
]
Kadena.Types.KeyPair.new(keypair_values)
Adding capabilities to existing keypair:
clist =
Kadena.Types.CapsList.new([
[name: "gas", args: ["COIN.gas", 0.02]],
[name: "transfer", args: ["COIN.transfer", "key_1", 50, "key_2"]]
])
secret_key = "secret_key_value"
{:ok, %Kadena.Types.KeyPair{} = keypair} = Kadena.Cryptography.KeyPair.from_secret_key(secret_key)
keypair_with_clist = Kadena.Types.KeyPair.add_caps(keypair, clist)
SignersList
There are two ways to create a list of signers:
# with Keywords
signer1 = [pub_key: "pub_key_1"]
signer2 = [pub_key: "pub_key_2"]
# with Signer structs
signer1 = Kadena.Types.Signer.new([pub_key: "pub_key_1"])
signer2 = Kadena.Types.Signer.new([pub_key: "pub_key_2"])
Kadena.Types.SignersList.new([signer1, signer2])
Development
- Install any Elixir version above 1.13.
- Compile dependencies:
mix deps.get - Run tests:
mix test.
Want to jump in?
Check out our Good first issues, this is a great place to start contributing if you're new to the project!
We welcome contributions from anyone! Check out our contributing guide for more information.
Changelog
Features and bug fixes are listed in the CHANGELOG file.
Code of conduct
We welcome everyone to contribute. Make sure you have read the CODE_OF_CONDUCT before.
Contributing
For information on how to contribute, please refer to our CONTRIBUTING guide.
License
This library is licensed under an MIT license. See LICENSE for details.
Acknowledgements
Made with 💙 by kommitters Open Source