C# alternative for the chia-dev-tools encode and decode cli commands


I am using c#, and need a code fix to convert the address to puzzle_hash and vice versa. I see that the chia-dev-tools provides us a cli command to execute the same. However when i try to install the library, i always run into errors as follows.

Can some one please help me with an approach in c# on the same?

If you already have chia-blockchain installed in the same environment, there could be a conflict between the built-in installation of chia-dev-tools and the one you are trying to install. Are you sure you can’t use them already?

If you don’t have chia-blockchain installed in the same environment, try uninstalling the old version before reinstalling the new one, or creating a new virtual environment with python3 -m venv venv or the like before installing it to prevent dependency conflicts.

Let me know how it goes!

chia-dotnet has Bech32M that you can use to convert the address to/from puzzle hash.

// puzz_hash:      eff07522495060c066f66f32acc2a77e3a3e737aca8baea4d1a64ea4cdc13da9

// > cdv encode 9e2e4b1edd32baedf2efc5bf9e43f0d95cc711a1cbe4c73046d2bbdce8c09f05 --prefix txch
// txch1nchyk8kax2awmuh0ckleuslsm9wvwydpe0jvwvzx62aae6xqnuzs0hzeea
// > cdv decode txch1nchyk8kax2awmuh0ckleuslsm9wvwydpe0jvwvzx62aae6xqnuzs0hzeea
// 9e2e4b1edd32baedf2efc5bf9e43f0d95cc711a1cbe4c73046d2bbdce8c09f05

using chia.dotnet.bech32;

var puzz_hash = "9e2e4b1edd32baedf2efc5bf9e43f0d95cc711a1cbe4c73046d2bbdce8c09f05";

var bech32 = new Bech32M("txch");
var address = bech32.PuzzleHashToAddress(puzz_hash);

var _puzz_hash = Bech32M.AddressToPuzzleHashString(address);

1 Like