API for address wallet creation from custom seed and asset transfer


#1

Please, let me know where to find some API or javascripts for:

a) address creation from custom seed
b) asset transfers

I am willing to launch a custom wallet for my token (in php) and the above functions would be enough for me.

Thanks in advance.


#2

a) get_address_from_seed( $seed )
b) curve25519_sign( $msg, $key )

My PHP library does not complete yet, but you can use this example of asset transfer v2:

    $tx = '';
    $tx .= chr( 4 );
    $tx .= chr( 2 );
    $tx .= $pub;
    $tx .= $asset ? chr( 1 ) : chr( 0 );
    $tx .= $asset ? $crypto->b58_decode( $asset ) : '';
    $tx .= $afee ? chr( 1 ) : chr( 0 );
    $tx .= $afee ? $crypto->b58_decode( $afee ) : '';
    $tx .= pack( 'J', $timestamp );
    $tx .= pack( 'J', $amount );
    $tx .= pack( 'J', $fee );
    $tx .= $crypto->b58_decode( $to );
    $tx .= pack( 'n', 0 ); // empty attachment
    
    $sign = $crypto->sign( $tx, $priv );

    $tx = [];
    $tx['version'] = 2;
    $tx['type'] = 4;
    $tx['sender'] = $sender;
    $tx['senderPublicKey'] = $crypto->b58_encode( $pub );
    $tx['recipient'] = $to;
    if( $asset ) $tx['assetId'] = $asset;
    $tx['amount'] = $amount;
    if( $afee ) $tx['feeAssetId'] = $afee;
    $tx['fee'] = $fee;
    $tx['timestamp'] = $timestamp;
    $tx['proofs'] = [ $crypto->b58_encode( $sign ) ];

Then broadcast json_encode( $tx ) to /transactions/broadcast on any node.


#3

Thank you @deemru.

Any information to get and post transactions on nodes from php scripts will be highly appreciated.


#4

Very basic broadcast of the $tx above:

    if( false === ( $ch = curl_init() ) )
        exit( 'curl_init failed' );

    if( false === curl_setopt_array( $ch, array (
        CURLOPT_HTTPHEADER      => array( 'Content-Type: application/json', 'Accept: application/json' ),
        CURLOPT_URL             => WAVES_HOST . '/transactions/broadcast',
        CURLOPT_POSTFIELDS      => json_encode( $tx ),
    ) ) )
        exit( 'curl_setopt_array failed' );

    $json = curl_exec( $ch );

    if( 0 != ( $errorCode = curl_errno( $ch ) ) )
        $errorMsg = curl_error( $ch );

    curl_close( $ch );

    if( $errorCode )
        exit( "curl_errno = $errorCode ($errorMsg)" );

    if( !( $json = json_decode( $json ) ) )
        exit( 'json_decode failed' );