我可以使用带有api的createAccountAddress函数创建eth接收地址吗?

时间:2017-12-22 07:11:35

标签: coinbase-api

我正在写一个script,它应该生成新的coinbase eth address。当我尝试createAccountAddress函数时,它似乎只为btc创建地址。有关如何使用此功能创建eth地址的任何帮助

$address = new Address([
'name' => 'my address'
]);

$add = $client->createAccountAddress($account, $address);

2 个答案:

答案 0 :(得分:1)

以下是获取ETH地址的请求代码 Dnt忘记输入您的api密钥,密码和ETH帐户ID

享受

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);
require __DIR__ . '/vendor/autoload.php';

use Coinbase\Wallet\Client;
use Coinbase\Wallet\Configuration;
use Coinbase\Wallet\Resource\Address;
use Coinbase\Wallet\Resource\Account;

$configuration = Configuration::apiKey('Enter Api Key','Enter Api Secret'); //update ur key and secrete
$client = Client::create($configuration);
$accountId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";  //Put Etheruem Account Id Here / You can get it by going to coinbase or calling get account here by api

$account = $client->getAccount($accountId);


$address = new Address([
'name' => 'New Address'
]);


$add = $client->createAccountAddress($account, $address);
$addressId = $client->getAccountAddresses($account);
$addresses = $client->getAccountAddress($account, $addressId->getFirstId());
$addo = json_encode($addresses->getAddress());
$addoo = str_replace('"', "", $addo);
echo $addoo;

?>

答案 1 :(得分:0)

是的,该线程已经很老了,但是api版本与(afaik)现在使用的相同。我没有足够的声誉分数来回复。

如果在多个人可以同时访问的地方(例如在Web服务器上)使用前一个答案,则它可能具有潜在的竞争条件。根据地址的使用方式,可能会混淆付款。

要解决此问题,请替换最后一位

$add = $client->createAccountAddress($account, $address); 
$addressId = $client->getAccountAddresses($account); 
$addresses = $client->getAccountAddress($account, $addressId->getFirstId()); 
$addo = json_encode($addresses->getAddress()); 
$addoo = str_replace('"', "", $addo); 
echo $addoo;

?>

使用

$add = $client->createAccountAddress($account, $address); 
echo $add->getAddress();

?>