Wolfram Computation Meets Knowledge

Third-Generation Blockchain Functionality with Tezos and the Wolfram Language

Third-Generation Blockchain Functionality with Tezos and the Wolfram Language

As CEO of Wolfram Blockchain Labs (WBL), I think one of the most exciting parts of my job is collaborating with other leaders in the blockchain space to expand tools for developers and business use cases. For several years now, we’ve been adding a steady stream of blockchain functionality into the Wolfram Language to enable development of knowledge-based distributed applications and computational contracts. You may have noticed the growing number of popular blockchains (ARK, Bitcoin, bloxberg, Cardano, Ethereum, MultiChain…) partnering with us and integrating into our platform. It’s already led to some cool explorations, and we have a lot more in the pipeline.

Today, WBL is happy to announce its latest such collaboration, a partnership with TQ Tezos. That includes Tezos blockchain integration in the Wolfram Language, which is great news for smart contract developers and enthusiasts. But that’s just the beginning. Our long-term plans include a lot of big ideas that we think everyone will be excited about!

Complementary Collaboration

A Tezos-Wolfram partnership made sense from the start. We’ve worked to build up Wolfram Language support for third-generation blockchains, making Tezos integration an easy and intuitive part of our system. WBL has long had a particular focus on enabling smart contracts, and WBL and TQ Tezos have developed an oracle to provide Wolfram|Alpha data to Tezos smart contract developers.

One of the most exciting aspects of Tezos is its friendliness to formal verification. TQ Tezos has used the Mi-Cho-Coq framework to create a high degree of assurance that the oracle contract exhibits the same, predictable behavior every time it is called.

We also share the broader goal of democratizing technology. Tezos uniquely uses on-chain mechanisms for governance, which means that the people running nodes are the ones making decisions. Anyone interacting with the blockchain gets a vote—like citizens in a worldwide digital community. Wolfram has a history of making knowledge and computation widely available with Wolfram|Alpha, the Wolfram Cloud and the Wolfram Resource System.

The Foundation: Blockchain Integration

So, what could someone do right now with Wolfram Language access to the Tezos blockchain? To start, you can use BlockchainBlockData to retrieve data from Tezos (in this case, the most recent entry block):

BlockchainBlockData
BlockchainBlockData
&#10005

BlockchainBlockData[Last, BlockchainBase -> "Tezos"] // Dataset

To specify an address on the blockchain, use BlockchainKeyEncode with a generated PrivateKey (which uses the elliptic curves used in the Tezos ecosystem):

tezosAddress = BlockchainKeyEncode
&#10005

tezosAddress = BlockchainKeyEncode[PrivateKey[
Association[
   "Type" -> "EdwardsCurve", "CurveName" -> "ed25519", 
    "PrivateByteArray" -> ByteArray[{230, 223, 162, 157, 26, 105, 184,
       169, 145, 106, 12, 204, 35, 71, 36, 93, 34, 9, 37, 7, 155, 95, 
      209, 22, 37, 209, 4, 254, 62, 16, 142, 88}], 
    "PublicByteArray" -> ByteArray[{137, 139, 124, 252, 66, 254, 126, 
      158, 120, 84, 94, 58, 250, 94, 109, 166, 174, 191, 195, 209, 
      182, 183, 7, 72, 38, 21, 112, 86, 73, 12, 175, 204}], 
    "PublicCurvePoint" -> {
     15783581147550366836542846006538900489655451279646389129589897096\
19011472361, 
      3468505952679969615990774873903380786368045635621138588516215319\
7588300204937}]], "Address", BlockchainBase -> {"Tezos", "Testnet"}]

Given this address, BlockchainAddressData will provide a range of information:

BlockchainAddressData
&#10005

BlockchainAddressData[tezosAddress, 
  BlockchainBase -> {"Tezos", "Testnet"}] // Dataset

Here’s the current balance at that address:

balance = %
&#10005

balance = %["Balance"]

You can also create smart contracts to put your own data on the Tezos blockchain. To achieve that, you’d start by creating a transaction operation with BlockchainTransaction:

tx = BlockchainTransaction
&#10005

tx = BlockchainTransaction[<|
   
   "BlockchainBase" -> {"Tezos", "Testnet"},
   "Type" -> "Origination",
   "Sender" -> tezosAddress,
   "Balance" -> 100,
   "Contract" -> <|
     "Storage" -> <|"string" -> "hello"|>,
     "Code" -> {<|"prim" -> "parameter", 
        "args" -> {<|"prim" -> "string"|>}|>, <|"prim" -> "storage", 
        "args" -> {<|"prim" -> "string"|>}|>, <|"prim" -> "code", 
        "args" -> {{<|"prim" -> "CAR"|>, <|"prim" -> "NIL", 
            "args" -> {<|"prim" -> "operation"|>}|>, <|"prim" -> 
             "PAIR"|>}}|>}
     |>
   |>]

Then you can sign the operation by passing the BlockchainTransaction object and the appropriate PrivateKey to BlockchainTransactionSign:

txSigned = BlockchainTransactionSign
&#10005

txSigned = BlockchainTransactionSign[tx, PrivateKey[
Association[
   "Type" -> "EdwardsCurve", "CurveName" -> "ed25519", 
    "PrivateByteArray" -> ByteArray[{230, 223, 162, 157, 26, 105, 184,
       169, 145, 106, 12, 204, 35, 71, 36, 93, 34, 9, 37, 7, 155, 95, 
      209, 22, 37, 209, 4, 254, 62, 16, 142, 88}], 
    "PublicByteArray" -> ByteArray[{137, 139, 124, 252, 66, 254, 126, 
      158, 120, 84, 94, 58, 250, 94, 109, 166, 174, 191, 195, 209, 
      182, 183, 7, 72, 38, 21, 112, 86, 73, 12, 175, 204}], 
    "PublicCurvePoint" -> {
     15783581147550366836542846006538900489655451279646389129589897096\
19011472361, 
      3468505952679969615990774873903380786368045635621138588516215319\
7588300204937}]]]

Finally, the contract is submitted to the blockchain using BlockchainTransactionSubmit:

submitted = BlockchainTransactionSubmit
&#10005

submitted = BlockchainTransactionSubmit[txSigned]

And with just a few simple lines of code, you’ve deployed a smart contract to the Tezos ecosystem. Once the transaction operation is on the blockchain (which can sometimes take a few minutes), you can verify that the balance has been updated:

newBalance = BlockchainAddressData
&#10005

newBalance = 
 BlockchainAddressData[tezosAddress, "Balance", 
  BlockchainBase -> {"Tezos", "Testnet"}]

The total transaction amount is equal to the 100 mutez payment plus a 76,232 mutez fee:

balance - newBalance
&#10005

balance - newBalance

The details of the fees can be inspected by using BlockchainTransactionData and passing the transaction ID of the submitted BlockchainTransaction:

BlockchainTransactionData
&#10005

BlockchainTransactionData[submitted["TransactionID"], "Fees", 
  BlockchainBase -> {"Tezos", "Testnet"}] // Dataset

This powerful simplicity is a core advantage of any Wolfram Language integration: you don’t have to be a developer to get serious work done.

More in the Works

The ultimate result will be an expansive toolkit that makes Tezos development available to everyone, regardless of programming skill. We have plans to extend these capabilities in several key areas within the Tezos ecosystem: analytics, computational facts delivery and blockchain educational information. WBL is also exploring how we might begin to bake on Tezos, our first tentative foray into how staking works on a blockchain network.

This and our other blockchain partnerships help move WBL toward the larger goal of bringing computational reform to the financial industry: smart contracts, symbolic data and smart reporting. We’re always looking for more ways to expand what we are doing with blockchains and other decentralized technologies. Keep an eye out for our next big announcement!

Get your free Wolfram|One trial to start writing your own smart contracts, or connect with WBL to find out about integrating your blockchain into the Wolfram Language.

Comments

Join the discussion

!Please enter your comment (at least 5 characters).

!Please enter your name.

!Please enter a valid email address.

1 comment

  1. Please support Liquidity as a Code option, I do not want to have to write contracts in a kinda-LISP :-)

    Reply