can I create eth receive address using createAccountAddress function with api? - coinbase-api

I am writing a script which should generate new coinbase eth address. When I try createAccountAddress function it seems only creating address for btc. Any help regarding how to create eth address with this function
$address = new Address([
'name' => 'my address'
]);
$add = $client->createAccountAddress($account, $address);

Here is the requested code to get ETH Address
Dnt forget to Put your api key, secret , and ETH account id
Enjoy
<?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;
?>

Yes, this thread is quite old, but the api version is (afaik) the same in use today. I do not have enough reputation points to reply.
The previous answer has a potential race condition if this is used where multiple people can be accessing at the same time such as on a web server. Depending on how the address is used payments could be confused.
To correct this problem replace the last bit
$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;
?>
with
$add = $client->createAccountAddress($account, $address);
echo $add->getAddress();
?>

Related

Error with google Api to get user'sEmail Address

i am using Google_Service_Gmail() to get the users'info. but getting issue "PHP Fatal error: Cannot call constructor on line 84 in '.../service/Gmail.php'"
here is code image
$obj = new GoogleOAuth();
$obj->access_token =$access;
$obj->refresh_token = $refresh;//$data['refresh_token'];
$obj->token_type = $tokentype;
$obj->expires_in = 3600;
$arr = array();
$client = new Google_Client($arr);
$client->setApplicationName('Get Email');
$client->setClientId('[CLIENT-ID]');
$client->setClientSecret('[CLIENT-SECRET]');
$client->setRedirectUri('[REDIRECT-URI]');
$client->setScopes(Google_Service_Gmail::GMAIL_READONLY);
$client->setAccessType('offline');
$authUrl = $client->createAuthUrl();
$token = json_encode($obj);
if (!$client->getAccessToken()) {
$client->setAccessToken($token);
}
$gmail = new Google_Service_Gmail($client);
return $gmail->getEmailAddress();
the code of Gmail.php provided in lib files is
here is the code of the file in google api php client library
I suggest you start your code with the Gmail quickstart [1] so you can successfully retrieve the Gmail Service, with this object you can access to the "user" property which is a "Users_Resource" [2], apply the getProfile method to obtain the "Gmail_Profile" [3] from where you can get the email address:
$user = $gmail->user;
$email = $user->getProfile("me")->getEmailAddress( );
[1] https://developers.google.com/gmail/api/quickstart/php
[2] https://developers.google.com/resources/api-libraries/documentation/gmail/v1/php/latest/class-Google_Service_Gmail_Users_Resource.html
[3] https://developers.google.com/resources/api-libraries/documentation/gmail/v1/php/latest/class-Google_Service_Gmail_Profile.html

How to Unserialize this data in wordpress

CURRENT ISSUE: I am making one plugin for listing users with there user role in WP_LIST_TABLE table.
This is my query
$this->items = $wpdb->get_results($wpdb->prepare("SELECT {$wpdb->users}.*, {$wpdb->usermeta}.meta_value as roles FROM {$wpdb->users}
LEFT JOIN {$wpdb->usermeta} ON {$wpdb->users}.ID = {$wpdb- >usermeta}.user_id
WHERE {$wpdb->usermeta}.meta_key = '{$wpdb->get_blog_prefix()}capabilities'
ORDER BY {$wpdb->users}.display_name", $per_page, $paged), ARRAY_A);
It display out like This
[roles] => a:1:{s:13:"administrator";b:1;}
How to Unserialize this data. and I want to display the First name too using this query please help me
Finally this helps me.
$input = unserialize($item['roles']);
$result = array();
foreach($input as $key => $value){
$result[] = $key;
}
$userRole = implode(",", $result);
return $userRole;
Try below code:
foreach($this->items as $value){
echo $value->COLUMN_NAME ."<br>";
}
Please change the COLUMN_NAME to whichever column you want to display. If there's a column named e_name, then write "$value->e_name".
Its tried and tested. It works for me. Let me know if it works for you!

Get user uid from name (Drupal 7)

I can't figure out how to get an user's UID knowing the user's name.
The user's name will be entered by a variable. I just need to pick up the UID in another variable.
I've found this code, which would be perfect, but it doesn't work on Drupal 7:
$account = user_load(array('name' => check_plain($name)));
Can anybody help me?
Thank you very much!!
try
$user = user_load_by_name($username);
$user_id = $user->uid;
or you can use
function get_uid($username)
{
// Function that returns the uid based on the username given
$user = db_fetch_object(db_query("SELECT uid FROM users WHERE name=':username'", array(":username" => $username)));
return $user->uid;
}
One way to look up the user is to use the entity_load('user');. Here is an example how to do it:
// Add the user you want to find here
$user_to_lookup = 'test';
$users = entity_load('user');
$found_user = null;
foreach ($users as $user) {
if ($user->name == $user_to_lookup ) {
$found_user = $user;
}
}
The user object is stored in $found_user now. Note that its an stdClass so you need to use the arrow notation to access the properties. For example to access mail write $found_user->mail.

How to fetch the result from database in vtiger crm?

I am using vtiger 6.1.0 version.I want to fetch the user details from the database in the vtiger.
My code:
require_once('include/database/PearDatabase.php');
$db = PearDatabase::getInstance();
$query8 = "SELECT id from vtiger_users where is_admin=?";
$result8 =$db->pquery($query8, array("on"));
echo $num_rows = $db->num_rows($result8);
for($i=0; $i<$num_rows; $i++) {
echo $row = $db->query_result_rowdata($result8, $i,'id');
}
While using this code, the total number of rows is printed, but each id can not be fetched, showing some internal server error. Please help me!
You can pass only two argument in query_result_rowdata function.
Please see function in include/database/PearDatabase.php file.
function raw_query_result_rowdata(&$result, $row=0) {
if (!is_object($result))
throw new Exception("result is not an object");
$result->Move($row);
$rowdata = $this->change_key_case($result->FetchRow());
return $rowdata;
}
So please use like that, it work for me.
$index = 0;
foreach($listViewEntries as $recordId => $record) {
$rawData = $db->query_result_rowdata($listResult, $index++);
}

Prestashop 1.4.3 I need to get a database value and use it in MailAlerts module

I have asked this question on the Prestashop forum, but haven't had a reply as of yet.
I need to be able to add a sagepay code to the new order email used in mailalert module.
What I have is;
// Filling-in vars for email
$template = 'new_order';
$subject = $this->l('New order');
$spvtxc = Db::getInstance()->ExecuteS("SELECT vendortxcode FROM `"._DB_PREFIX_."sagepay_transactions` WHERE id_cart = '$order->id_cart'");
...
$templateVars = array(
'{firstname}' => $customer->firstname,
'{lastname}' => $customer->lastname,
...
'{sagepay_no}' => $spvtxc,
...
);
Every time i test a transaction the $spvtxc returns 'ARRAY'.
I have tried;
$spvtxc = '5';
As Expected this returns 5 as the sagepay number, so I'm confident the variables are being called and added to the email.
And I tried;
$spvtxc = Db::getInstance()->ExecuteS("SELECT vendortxcode FROM `"._DB_PREFIX_."sagepay_transactions` WHERE id_cart = '2'");
So this should set $spvtxc to the value that is definatly there (i manually added it in the database), but this still returned 'ARRAY'.
If anyone can point out what I have missed, it is greatly appriceated.
As I was only needing to return a single value, I should have used getValue function instead of ExecuteS.
$spvtxc = Db::getInstance()->getValue("SELECT vendortxcode FROM `"._DB_PREFIX_."sagepay_transactions` WHERE id_cart = '$order->id_cart'");
This returned the value.

Resources