Skip to content

Instantly share code, notes, and snippets.

@Coding-Enthusiast
Created June 8, 2020 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Coding-Enthusiast/5e58b3ddc2161c853562bc483beddf69 to your computer and use it in GitHub Desktop.
Save Coding-Enthusiast/5e58b3ddc2161c853562bc483beddf69 to your computer and use it in GitHub Desktop.
Showcase bitcoin address creation using any script
using Autarkysoft.Bitcoin;
using Autarkysoft.Bitcoin.Blockchain;
using Autarkysoft.Bitcoin.Blockchain.Scripts;
using Autarkysoft.Bitcoin.Blockchain.Scripts.Operations;
using Autarkysoft.Bitcoin.Cryptography.Asymmetric.KeyPairs;
using Autarkysoft.Bitcoin.Cryptography.Hashing;
using Autarkysoft.Bitcoin.Encoders;
public class AddressPlayground
{
public void BuildAddresses()
{
Address addr = new Address();
using PrivateKey key = new PrivateKey("KzLvnctuw7tMdg5hv1NXj4X515rbweDsgoyigtDgGgsqV9dW2kNo");
var pub = key.ToPublicKey();
var scr = new PubkeyScript();
scr.SetToP2PK(pub, true);
string p2sh_p2pk = addr.GetP2sh(scr);
scr.SetToP2PKH(pub, true);
string p2sh_p2pkh = addr.GetP2sh(scr);
var ops = new IOperation[]
{
new PushDataOp(UnixTimeStamp.GetEpochUtcNow()),
new CheckLocktimeVerifyOp(),
new DROPOp(),
new DUPOp(),
new Hash160Op(),
new PushDataOp(new Ripemd160Sha256().ComputeHash(pub.ToByteArray(true))),
new CheckSigOp(),
};
scr = new PubkeyScript(ops);
string scrhex = scr.Data.ToBase16();
string p2sh_script = addr.GetP2sh(scr);
var rdm = new RedeemScript();
rdm.SetToMultiSig(1, new PublicKey[] { pub });
string p2sh_multi = addr.GetP2sh(rdm);
string p2wsh = addr.GetP2wsh(scr, 0);
var anyoneCanSpend = new RedeemScript(new IOperation[] { new PushDataOp(OP._1) });
string anyoneAddress = addr.GetP2sh(anyoneCanSpend);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment