PHP WebShell
Текущая директория: /var/www/bitcardoApp
Просмотр файла: create_primary_wallet_eth_usdt_erc20.php
<?php
/**
* create_primary_wallet_eth_usdt_erc20.php
*
* Creates ONE primary wallet on BitGo MAINNET for:
* - ETH
* - USDT_ERC20 (USDT token on Ethereum)
*
* NOTE:
* - USDT-ERC20 uses the same Ethereum addresses as the ETH wallet.
* - On BitGo, the token id is: eth:usdt
*
* HOW TO USE
* 1) Set the constants below (ESPECIALLY ACCESS TOKEN + ENTERPRISE).
* 2) Run: php create_primary_wallet_eth_usdt_erc20.php
* or hit it in the browser.
*/
header('Content-Type: application/json');
// -------------------- CONFIG (EDIT THESE) --------------------
// Choose what you’re creating:
// 'ETH' => plain Ethereum wallet
// 'USDT_ERC20' => ETH wallet but labeled for USDT-ERC20 usage
const COIN = 'USDT_ERC20';
// Your working BitGo Express instance (we already confirmed ping here!)
const BITGO_EXPRESS_URL = 'http://127.0.0.1:3090';
const BITGO_ACCESS_TOKEN = 'v2xdf9e1719c05e56c1bded9b5f32664bd850e4a23c6d8b48a78814687fa626388d';
const BITGO_ENTERPRISE_ID = '640b9f95f5ca2c31b3a171a11555578b'; // your enterprise
const BITGO_WALLET_PASSPHRASE = 'CorrectHorse!';
// ------------------------------------------------------------
function fail($msg, $code = 400) {
http_response_code($code);
echo json_encode(['ok' => false, 'error' => $msg], JSON_PRETTY_PRINT);
exit;
}
function bitgo_request($method, $url, $payload = null) {
$ch = curl_init($url);
$headers = [
'Authorization: Bearer ' . BITGO_ACCESS_TOKEN,
'Content-Type: application/json',
];
$opts = [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_TIMEOUT => 60,
];
if (strtoupper($method) === 'POST') {
$opts[CURLOPT_POST] = true;
if ($payload !== null) {
$opts[CURLOPT_POSTFIELDS] = json_encode($payload);
}
}
curl_setopt_array($ch, $opts);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curlErr = curl_error($ch);
curl_close($ch);
if ($response === false) {
fail("cURL error: {$curlErr}", 500);
}
$data = json_decode($response, true);
if ($httpCode < 200 || $httpCode >= 300) {
fail([
'message' => "BitGo returned HTTP {$httpCode}",
'endpoint' => $url,
'request' => $payload,
'response' => $data ?: $response
], 502);
}
return $data;
}
// -------------------- COIN MAPPING --------------------
// Internal coin selections -> BitGo coin code
$coinMap = [
'ETH' => 'eth',
'USDT_ERC20' => 'eth', // still an ETH wallet, used for USDT ERC20 (eth:usdt)
];
$requestedCoin = strtoupper(trim(COIN));
if (!isset($coinMap[$requestedCoin])) {
fail("Unsupported COIN '" . COIN . "'. Use 'ETH' or 'USDT_ERC20'.");
}
$bitgoCoin = $coinMap[$requestedCoin];
// -------------------- LABEL & PAYLOAD --------------------
if ($requestedCoin === 'USDT_ERC20') {
$labelCoin = 'USDT-ERC20 (ETH wallet)';
} else {
$labelCoin = 'ETH';
}
$label = "Primary {$labelCoin} Wallet - " . date('Ymd-His');
$payload = [
'label' => $label,
'passphrase' => BITGO_WALLET_PASSPHRASE,
];
if (!empty(BITGO_ENTERPRISE_ID) && BITGO_ENTERPRISE_ID !== 'YOUR_ENTERPRISE_ID_HERE') {
$payload['enterprise'] = BITGO_ENTERPRISE_ID;
}
// -------------------- CREATE WALLET --------------------
$createUrl = rtrim(BITGO_EXPRESS_URL, '/') . "/api/v2/{$bitgoCoin}/wallet/generate";
$wallet = bitgo_request('POST', $createUrl, $payload);
// -------------------- EXTRACT DATA --------------------
$walletId = $wallet['id'] ?? null;
$walletCoin = $wallet['coin'] ?? $bitgoCoin;
$walletLbl = $wallet['label'] ?? $label;
$recvAddr = $wallet['receiveAddress']['address'] ?? null;
$keyIds = $wallet['keys'] ?? [];
$keyDetails = [];
$bitgoKeycard = null;
// Fetch keychains so you have the BitGo keycard metadata
foreach ($keyIds as $kid) {
$kUrl = rtrim(BITGO_EXPRESS_URL, '/') . "/api/v2/key/{$kid}";
$k = bitgo_request('GET', $kUrl);
$entry = [
'id' => $k['id'] ?? null,
'source' => $k['source'] ?? null,
'isBitGo' => $k['isBitGo'] ?? null,
'pub' => $k['pub'] ?? null,
'encryptedPrv?' => isset($k['encryptedPrv']),
'derivation' => $k['derivationPath'] ?? null,
'created' => $k['createTime'] ?? null,
'updated' => $k['updatedTime'] ?? null,
'tags' => $k['tags'] ?? null,
];
$keyDetails[] = $entry;
if (!empty($entry['isBitGo']) || (isset($entry['source']) && $entry['source'] === 'bitgo')) {
$bitgoKeycard = [
'id' => $entry['id'],
'source' => $entry['source'],
'pub' => $entry['pub'],
'derivation' => $entry['derivation'],
'created' => $entry['created'],
'updated' => $entry['updated'],
'note' => 'BitGo-held keychain metadata (public).',
];
}
}
// -------------------- OUTPUT --------------------
$notes = null;
if ($requestedCoin === 'USDT_ERC20') {
$notes = 'USDT-ERC20 uses these ETH addresses. On BitGo the token id is eth:usdt. ' .
'Fund ETH for gas; USDT balance will appear as a token on top of this wallet.';
}
echo json_encode([
'ok' => true,
'requested' => $requestedCoin,
'createdFor' => $walletCoin,
'label' => $walletLbl,
'notes' => $notes,
'wallet' => [
'id' => $walletId,
'coin' => $walletCoin,
'receiveAddress' => $recvAddr,
],
'keys' => [
'allKeychains' => $keyDetails,
'bitgoKeycard' => $bitgoKeycard,
],
], JSON_PRETTY_PRINT);
Выполнить команду
Для локальной разработки. Не используйте в интернете!