October 2, 2026

CScript to CPubKey or derive CPubKey from CScript

Please can someone advise if it is possible to derive the CPubKey from a CSript object? Provided i get it up with an address before hand,

I can use numerous functions to attain all the info from the CPubKey using functions, but can you make a CPubKey from a CSript?

Or are they too much chalk and cheese?

Thank you,

EDIT:
Following the first answer I’ve tried the below to no joy. The script returns totally empty:

CScript scriptPubKey1;
CBitcoinAddress address("L4VPgtoBtuxsYMgyrRvQRadSV1Y139TDfd");
scriptPubKey1.SetDestination(address.Get());

CScript::const_iterator it = scriptPubKey1.begin(); // or specifically, the location of the pubkey in the CScript object
opcodetype opcode;
std::vector<unsigned char> data;
scriptPubKey1.GetOp(it, opcode, data); // data now contains the byte vector

CPubKey pubkey3 = CPubKey(data);
Previous Article

Networking in cryptocurrency

Next Article

BCH ABC testnet Faucet?