# Sample of using bitcoinjs-lib with Counterparty

**URL:** <https://forums.counterparty.io/t/sample-of-using-bitcoinjs-lib-with-counterparty/677>\
**Category:** Counterparty\
**Created:** [January 14, 2015, 7:21am UTC](https://forums.counterparty.io/t/sample-of-using-bitcoinjs-lib-with-counterparty/677 "2015-01-14T07:21:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexnsk](https://yyz2.discourse-cdn.com/flex004/user_avatar/forums.counterparty.io/alexnsk/32/52_2.png) [@alexnsk](https://forums.counterparty.io/u/alexnsk)\
**Post date:** [January 14, 2015, 7:21am UTC](https://forums.counterparty.io/t/sample-of-using-bitcoinjs-lib-with-counterparty/677/1 "2015-01-14T07:21:51Z")

</div>

For any operation, which requires push data into blockchain, you need full set of cryptographic tools. Here we’ll show how to use bitcoinjs-lib to sign transactions and some other commands at browser’s side.

  

## Create wallet
Keys may be generated and sent to user or user could provide his own key.  
  
var key = Bitcoin.ECKey.makeRandom();  
var pk = key.toWIF(); // Private Key  
var address = key.pub.getAddress();  
address.version = ADDR\_VERSION; // 0x00 — mainnet, 0x6F — testnet  
// address.toString() — User’s address  
  

## Get existing address
Private key is not required for authorization, but should be provided by the user for transaction sign.  
  
try{ var addr = Bitcoin.Address.fromBase58Check(address);  
}catch(e){ // Invalid address  
}  

## Create asset
Three steps required:  
  

### Step 1: create asset with counterpartyd’s RPC
method: create\_issuance  
params: { “asset”: “asset name”, “source”: “issuer address”, “quantity”: issue in satoshis, “allow\_unconfirmed\_inputs”: true, “encoding”: “multisig”, “pubkey”: “public key for issuer address”  
}  
Result: hex-data of unsigned transaction.  
  

### Step 2: sign the transaction with bitcoinjs-lib
Private key provided by user.  
  
var key = Bitcoin.ECKey.fromWIF(‘private key’);  
var tx=Bitcoin.Transaction.fromHex(‘HEX-data from step 1’);  
tx.sign(0, key);  
tx.toHex(); // HEX-data of signed transation  
Result: hex-data of signed transaction.  
  

### Step 3: push transaction into blockchain
Send command using RPC of counterpartyd.  
  
method: broadcast\_tx  
params:{ “signed\_tx\_hex”:”HEX представление подписаной транзакции”  
}  
Result: hash of pushed transaction.  
  
Make sure that issuer address have at least 0.5XCP at balance. This is the fee for asset issuance. You may also issue asset with names like AXXXXXXX (where XXX are numbers) without fee.
