1

I have found this open source project that aims to create a typescript library to write smart contracts.

I had a look at the code but was not able to understand a couple of main pieces useful to understand the whole picture.

Of course the author is following the Plutus Core Specificiation in order to create the library, but to me is not clear where the actual serialization happen.

Also, when the serialization is done, how will be possible to push it to the computational layer of the blockchain? Should we crate a particular transaction containing the obtained binary code?

Thanks

1 Answer 1

1

Searching in the existing folders I ended up finding the UPLCEncoder implementation.

in particular, the class exposes a compile method that has the following signature:

compile( program: UPLCProgram ): BitStream

so it is something that given a UPLCProgram instance returns a BitStream; the implementation of the BitStream class suggest it is a wrapper ona bigint js primitive value used to store the compiled program.

back to the compile method; the library already supports hoisting; so the first part of the method is about inlining hoisted terms;

the actual compilation is forwarded to the encodeTerm method as we can see from

result.append(
    this.encodeTerm(
        progrTerm
    )
);

the implementation of encodeTerm is just an intermediate step to choose the encoding to use based on the actual UPLCTerm instance passed.

once encodeTerm understands the type of the terms calls the specific encoding function that translates 1:1 the UPLCTerm to binary (using BitStream) and calls again encodeTerm (mutually recursive) when necessary as in the case of Application encoding

const result = Application.UPLCTag;
this._ctx.incrementLengthBy( result.length );

result.append(
    this.encodeTerm( app.funcTerm ) 
);

result.append(
    this.encodeTerm( app.argTerm )
);

once compile returns the BitStream currently the solution is to use the toBuffer method to get a Buffer from it and convert it to the serialized hexadecimal string that can be submitted in a transaction, just like any other smart contract.

it has to be said that the project is quite new so I'm sure there will be a more direct way to obtain the hexadecimal string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.