use Modern::Perl; use LWP::UserAgent; use JSON; use Digest::SHA qw(hmac_sha256_base64 hmac_sha256_hex hmac_sha256); use MIME::Base64; use Time::Piece; my $uri = 'https://api-public.sandbox.pro.coinbase.com'; my $api_key = '6dc071df2d42724c019f79a53464d006'; my $secret = 'vjYZFn39LEFfbJ5z9QzdWt+HsahYTPvXInoYMD9Gq754FJL0evlGnHcTiaaITGF+6GfbyYnxoyCXji9OR1iEMw=='; my $passphrase = "There is no passphrase.", my $now = gmtime; my $timestamp = $now->datetime . ".000000Z"; my $request_method = "GET"; my $request_path = '/products'; my $body = ''; my $message = $timestamp . $request_method . $request_path . $body; my $decoded_secret = decode_base64($secret); my $signature_b64 = encode_base64( hmac_sha256($message, $decoded_secret) ); chomp($signature_b64); my $ua = LWP::UserAgent->new; $ua->agent ('Stock/1.0'); my $res = $ua->get( "$uri$request_path", 'CB-ACCESS-SIGN' => $signature_b64, 'CB-ACCESS-TIMESTAMP' => $timestamp, 'CB-ACCESS-KEY' => $api_key, 'CB-ACCESS-PASSPHRASE' => $passphrase, 'Content-Type' => 'application/json' ); if ($res->is_success) { say $res->decoded_content; } else { say "request failed."; say "status:", $res->as_string; }