vault module

On GreenAddress API, vault is the primary module for funds handling. Here you can “generate” new P2SH, the BIP32 “bitcoin addresses”, but also sign and transmit outgoing transactions.

Social transactions are supported too by GreenAddress API, and the BIP0070 payment protocol as well.

com.greenaddress.vault

com.greenaddress.vault.fund([subaccount][, return_pointer][, addr_type][, confidential])
Generate and return P2SH hash the user can pay to. This call is limited to 1000 P2SH per day for each wallet.
Check usage on Github: JS Example or look at our Python example

References:
Parameters:
  • subaccount (Int) – If not specified, default is main account.
  • return_pointer (boolean) – Whether to return BIP32 pointer number in addition to the script (default=false)
Returns:

hex encoded script

Return type:

String

com.greenaddress.vault.fund_receiving_id(receiving_id)
Returns a P2SH hash that anyone can pay to given receiving_id.
Check usage on Github: JS Example
Parameters:receiving_id (String) – The GreenAddress’ user receiving ID
Returns:base58 encoded P2SH address
Return type:String
com.greenaddress.vault.get_next_private_derived_pointer([subaccount])
Returns next unused EXTERNAL branch private key pointer.
Check usage on Github: JS Example
Parameters:subaccount (Number) – If not specified, default subaccount is Main.
com.greenaddress.vault.prepare_payreq(value, data[, priv_data])
Prepare BIP70 payment protocol transaction.
Check usage on Github: JS Example
Reference:
Parameters:
  • Number (value) – satoshis
  • data – data returned from process_bip0070_url
Returns:

same as prepare_tx

com.greenaddress.vault.prepare_redeposit(txouts[, priv_data])
Prepare nLockTime redeposit.
Check usage on Github: JS Example
Reference guide:
Parameters:Array (txouts) – [[txhash, out_n], ...]
Returns:same as prepare_tx
com.greenaddress.vault.prepare_sweep_social(pubkey[, use_electrum][, subaccount])
Prepare public key sweeping transaction.
Check usage on Github: JS Example
Parameters:
  • pubkey (Array) – pubkey bytes
  • use_electrum (Boolean) – whether to use Electrum servers to get the balance. If false, only GreenAddress transactions are considered.
Returns:

{‘tx’: hex, ‘prevout_scripts’: [hex, ...]}

com.greenaddress.vault.prepare_tx(value, rcpt_ad, add_fee, priv_data)
Parameters:
  • value (String) – satoshis as string.
  • rcpt_ad (String) – recipient address.
  • add_fee (String) – ‘sender’ or ‘recipient’ pays the fee
  • priv_data – external private transaction and other additional data {external_private: Boolean, pointer: Number, pubkey: bytes array, instant: Boolean, memo: String, minimize_inputs: Boolean}
  • priv_data.minimize_inputs – whether to optimize for minimum number of inputs instead of nLockTime expiring
Returns:

prep_info dictionary

{
    'tx': hexencoded binary unsigned transaction without signatures in redeem scripts,
    'prev_outputs': [
        {
            'script': hex,
            'value': satoshis,
            'branch': branch of users' pubkey in the redeem script,
            'pointer': pointer in the branch,
            'subaccount': Number
        }
    ],
    'change_pointer': Number,
    'requires_2factor': Boolean
}

The ‘tx’ returned contains the original unhashed prev_output script in its redeem script for each input. This original script can be used to generate the P2SH output script at the js side. This P2SH prev output script is needed to generate a signature.

com.greenaddress.vault.process_bip0070_url(url)
Returns BIP70 payment request data
Check usage on Github: JS Example
Reference:
Parameters:String (url) – payment request URL
Returns:{ ‘outputs’: [{‘amount’: satoshis, ‘address’: String}, ...], ‘merchant_data’: hex, ‘payment_url’: String, ‘payreq_url’: String, ‘payreq’: hex, ‘memo’: String, ‘requires_instant’: Boolean}
  • requires_instant field is deprecated, and BIP70 instant payments extension is still pending finalisation.
com.greenaddress.vault.send_raw_tx(rawtx_hex[, twofac_data][, priv_data])
Sign and send a hex-encoded transaction.
Parameters:
  • rawtx_hex (hexstring) – Raw hex representation of the transaction to sign and send.
  • twofac_data (dict) –

    optional 2FA data - keys:

    For all transactions – 2FA must be requested with action ‘send_raw_tx’ (for most cases), or ‘bump_fee’:
    - code
    - method
    For raw tx ‘simply spending’ some given amount of satoshi:
    - send_raw_tx_amount - spent satoshi amount (including fee)
    - send_raw_tx_fee - fee satoshi amount
    - send_raw_tx_recipient - recipient address
    - send_raw_tx_change_idx - change output index (-1 if no change)
    For raw tx ‘bumping fee’:
    - bump_fee_amount - satoshi amount of bumped fee
    For raw tx ‘simply spending’ some given amount of satoshi, below user’s spending limit (not requiring 2FA):
    - try_under_limits_spend - dict with keys amount (can be ‘any’), change_idx, fee (optional)
    For raw tx ‘bumping fee’, below user’s spending limit (not requiring 2FA):
    - try_under_limits_bump - satoshi amount of bumped fee
  • priv_data (dict) –

    optional additional transaction data - keys:

    - instant: boolean
    - memo: string
Returns:

dict - keys:

txhash: resulting tx hash
[new_limit]: optional amount of new spending limit after the transaction

com.greenaddress.vault.send_reddit(recipient, href)
com.greenaddress.vault.send_tx(signatures[, twofac_data])
The transaction must have been prepared using prepare_tx and signed client side.
Check usage on Github: JS Example
Reference:
Parameters:
  • signatures (Array) – list of hex-encoded user signatures in the same order as prev_outputs.
  • twofac_data – (code requested with action=’send_tx’) {method: ‘gauth’|’email’|’sms’|’phone’, code: String}
Returns:

hex encoded txhash.

Return type:

String

com.greenaddress.vault.set_scanning_key(subaccount, pointer, pubkey)
com.greenaddress.vault.sign_raw_tx(rawtx_hex[, twofac_data])
Sign a hex-encoded transaction.
Parameters:
  • rawtx_hex (hexstring) – Raw hex representation of the transaction to sign.
  • twofac_data (dict) – optional 2FA data - keys are the same as for the send_raw_tx RPC.
Returns:

dict - keys:

tx: resulting signed tx
[new_limit]: optional amount of new spending limit after the transaction