generate keys from random:
$keys = HDKeys::GenerateRandom();
generate keys from seed(NOT IMPLEMENTED YET):
$keys = HDKeys::FromSeed($seed);
create keys from private key:
$keys = HDKeys::FromPrivateKey($pk);
сreate wallet from hd keys:
$keys = new \velascrypto\HDKeys($keypair);
$wallet = $keys->Wallet();
сreate wallet from public key:
$wallet = new Wallet(hex2bin($pubKey));
get balance by wallet address:
$node_url = "https://testnet.velas.com/api/v1/" //testnet
$client = new HttpClient($node_url);
$balance = $client::$wallet->GetBalance($address);
get unspents by wallet address:
$client = new HttpClient($node_url);
$unspents = $client::$wallet->GetUnspent($address);
create, sign and convert transaction to json:
$tx = new Transaction($unspent, $amount, $keypair, $from, $to, $commission);
$tx = $tx->Sign();
$tx->ToJSON();
validate transaction
$client = new HttpClient($node_url);
$unspents = $client->GetUnspent($address);
$unspent = $unspents[0]; // unspent value must greater then amount plus commission
$keypair = HDKeys::FromPrivateKey(pk);
$tx = new Transaction($unspent, $amount, $keypair, $from, $to, $commision);
$tx = $tx->Sign();
echo "tx: " . $tx->ToJSON() . "\n";
$result = $client::$wallet->Validate($tx); // ok or not ok
broadcast transaction(send to net):
$client = new HttpClient($node_url);
$unspents = $client->GetUnspent($address);
$unspent = $unspents[0]; // unspent value must greater then amount plus commission
$keypair = HDKeys::FromPrivateKey(pk);
$tx = new Transaction($unspent, $amount, $keypair, $from, $to, $commision);
$tx = $tx->Sign();
echo "tx: " . $tx->ToJSON() . "\n";
$result = $client::$wallet->Send($tx); // ok or not ok
get transaction hashes in blocks of range from some height to last block
$client = new HttpClient(url);
$height = 0;
$txs = $client::$txs->getByHeight($height);
echo json_encode($txs);
$client = new HttpClient(url);
$hashes = [
"781b12dbe9a4e2546908759f00fdbda122cea4d432a4583dc1a2e3d4d6f66f18",
];
$txs = $client::$txs->getByHashes($hashes);