嗨,我正在php.api实现中尝试使用coinbase api正常工作,我可以检查余额,创建新地址,所有这些都工作正常。但是在请求比特币时面临问题。我正在关注coinbase official api librery,在提到的链接请求资金使用代码上记录的文件是
use Coinbase\Wallet\Enum\CurrencyCode;
use Coinbase\Wallet\Resource\Transaction;
use Coinbase\Wallet\Value\Money;
$transaction = Transaction::request([
'amount' => new Money(8, CurrencyCode::USD),
'description' => 'Burrito'
]);
$client->createAccountTransaction($transaction);
我完全按照他们的意思说,但是我遇到了错误,下面是我的代码
<?php
require_once('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;
$apiKey='xxxxxxx';
$apiSecret='xxxxxxx';
$configuration = Configuration::apiKey($apiKey, $apiSecret);
$client = Client::create($configuration);
$transaction = Transaction::request([
'amount' => new Money(8, CurrencyCode::USD),
'description' => 'Burrito'
]);
$client->createAccountTransaction($transaction);
echo json_encode($client->decodeLastResponse());
?>
错误是
致命错误:未捕获的TypeError:参数1传递给 Coinbase \ Wallet \ Client :: createAccountTransaction()必须是一个实例 Coinbase \ Wallet \ Resource \ Account的实例 给定的Coinbase \ Wallet \ Resource \ Transaction,称为 /file_path/file.php在第19行并在 / library_path /vendor/coinbase/coinbase/src/Client.php:359堆栈 跟踪:#0 /file_path/file.php(19): Coinbase \ Wallet \ Client-> createAccountTransaction(Object(Coinbase \ Wallet \ Resource \ Transaction))
1 {main}在第359行的/ library_path /vendor/coinbase/coinbase/src/Client.php中抛出
我尝试通过添加特定的帐户参数
$account=$client->getPrimaryAccount();
$transaction = Transaction::request([
'amount' => new Money(8, CurrencyCode::USD),
'description' => 'Burrito'
]);
$client->createAccountTransaction($account,$transaction);
然后我得到了错误异常To peremeter missing
,所以我将其添加到参数
Transaction::request([
'to'=>'test@mail.com',
'amount' => new Money(8, CurrencyCode::USD),
'description' => 'Burrito'
]);
现在错误是
致命错误:未捕获的TypeError:参数1传递给 Coinbase \ Wallet \ Resource \ Transaction :: setTo()必须是 Coinbase \ Wallet \ Resource \ Resource,给定的字符串,在 /home/exhakduz/api/vendor/coinbase/coinbase/src/Resource/Resource.php 在第70行并在/ library_path中定义 /vendor/coinbase/coinbase/src/Resource/Transaction.php:199堆栈 跟踪:#0 / library_path /vendor/coinbase/coinbase/src/Resource/Resource.php(70): Coinbase \ Wallet \ Resource \ Transaction-> setTo('test@mail.com')#1 / library_path /vendor/coinbase/coinbase/src/Resource/Resource.php(25): Coinbase \ Wallet \ Resource \ Resource-> updateAttributes(Array)#2 / library_path /vendor/coinbase/coinbase/src/Resource/Transaction.php(119): Coinbase \ Wallet \ Resource \ Resource-> __ construct('transaction',Array)
3 / library_path /vendor/coinbase/coinbase/src/Resource/Transaction.php(114):
Coinbase \ Wallet \ Resource \ Transaction-> __ construct('request',Array)#4 / library_path /receive.php(20): Coinbase \ Wallet \ Resource \ Transaction :: request(/ library_path中的Ar /vendor/coinbase/coinbase/src/Resource/Transaction.php,第199行
答案 0 :(得分:0)
您的呼叫还应引用Array3dG.fromInt(listOfInt)
:
new
答案 1 :(得分:0)
尝试
$client->createAccountTransaction($account, $transaction);
Transaction::request([
'toEmail'=>'test@mail.com',
'amount' => new Money(8, CurrencyCode::USD),
'description' => 'Burrito'
]);
$client->createAccountTransaction($account, $transaction);