我想发送btc使用我的帐户与api与php。
我试过github的coinbase api,它已经折旧了
https://github.com/coinbase/coinbase-php
当我尝试这段代码时,我得到了错误
require_once( __DIR__ . '/requires/coinbase/vendor/autoload.php');
use Coinbase\Wallet\Client;
use Coinbase\Wallet\Configuration;
use Coinbase\Wallet\Enum\CurrencyCode;
use Coinbase\Wallet\Resource\Transaction;
use Coinbase\Wallet\Value\Money;
$configuration = Configuration::apiKey($apiKey, $apiSecret);
$client = Client::create($configuration);
$transaction = Transaction::send([
'toBitcoinAddress' => "$bticoin_address",
'amount' => new Money($amount, CurrencyCode::USD),
'description' => 'Your first bitcoin!',
'fee' => '0.0001' // only required for transactions under BTC0.0001
]);
try {
$transaction = $client->createAccountTransaction($account, $transaction);
}
catch(Exception $e) {
echo $e->getMessage();
}我得到了这个错误
<b>Fatal error</b>: Uncaught TypeError: Argument 1 passed to Coinbase\Wallet\Exception\HttpException::exceptionClass() must be an instance of Psr\Http\Message\ResponseInterface, null given, called in /home/fiberpay/public_html/owner/requires/coinbase/vendor/coinbase/coinbase/src/Exception/HttpException.php on line 33 and defined in /home/fiberpay/public_html/owner/requires/coinbase/vendor/coinbase/coinbase/src/Exception/HttpException.php:98
Stack trace:
#0 /home/fiberpay/public_html/owner/requires/coinbase/vendor/coinbase/coinbase/src/Exception/HttpException.php(33): Coinbase\Wallet\Exception\HttpException::exceptionClass(NULL)
#1 /home/fiberpay/public_html/owner/requires/coinbase/vendor/coinbase/coinbase/src/HttpClient.php(137): Coinbase\Wallet\Exception\HttpException::wrap(Object(GuzzleHttp\Exception\RequestException))
#2 /home/fiberpay/public_html/owner/requires/coinbase/vendor/coinbase/coinbase/src/HttpClient.php(121): Coinbase\Wallet\HttpClient->send(Object(GuzzleHttp\Psr7\Request), Array)
#3 /home/fiberpay/public_html/owne in <b>/home/fiberpay/public_html/owner/requires/coinbase/vendor/coinbase/coinbase/src/Exception/HttpException.php</b> on line <b>98</b><br />有没有办法这样做??
我花了很多时间在谷歌上搜索,但仍然没有找到任何解决方案,这就是为什么我把它放在上面,也许我从那里得到了一些好的解决方案:)
最佳Regars
发布于 2021-04-08 22:28:58
我使用coinbase php库已经有4年了。当您收到该错误时,很可能是由于帐户凭据不正确。
此外,默认的github库在它的一个文件夹中有一个过期的上传证书。你得把它换掉。Coinbase PHP每次都很适合我。
发布于 2021-10-19 08:04:05
不使用coinbase PHP包装器,而使用coinbase API本身
要从一个coinbase帐户向另一个帐户汇款,可以使用以下代码
首先,获取api_key和api_secret
$private_key = 'Doadlraixxxxxx'; //Coinbase Private Key
$api_key = 'ysEZjjBxxxxx'; //Coinbase API KEY创建一个包含提取请求方法的新帐户对象将是POST,路径是API path,提取它的路径是/v2/ stdClass /:accountid/transactions,然后只需在此处输入私钥和API密钥。
$json = new stdClass();
$json->method = "POST";
$json->path = "/v2/accounts/".$account_id."/transactions";
$json->secretapikey = $private_key;
$json->apikey = $api_key;现在创建另一个stdClass,其中包含您的提款信息,如电子邮件、货币等
$body = new stdClass();
$body->type = "send";
$body->to = $to_email;
$body->amount = $amount;
$body->currency = $currency;然后,在下一步中,我们必须根据时间戳创建签名,为此我们必须创建当前时间、路径和$body stdClass的SHA256哈希
$result = json_encode($json);
$body = json_encode($body);
$time= time();
$sign = $time.$json->method.$json->path.$body;
$hmac = hash_hmac("SHA256", $sign, $json->secretapikey);我们的签名和正文已经准备好了,只需要把它张贴出来
$URL = "https://api.coinbase.com/v2/accounts/".$account_id."/transactions";
$header = array(
"CB-ACCESS-KEY:".$api_key,
"CB-ACCESS-SIGN:".$hmac,
"CB-ACCESS-TIMESTAMP:".time(),
"CB-VERSION:2019-11-15",
"Content-Type:application/json"
);
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
print_r($result);发送请求后,钱将被成功发送。
并且使用一些装饰代码,如下面的https://gist.github.com/AdityaEXP/27408bd361d5b8fcc9ac2bf459eb5303所示
https://stackoverflow.com/questions/65474174
复制相似问题