import requests


def push_transaction(transaction, testnet=False):
	"""
	Publish a transaction to the bitcoin blockchain
	:param transaction: hex string transaction code
	:param testnet: flag to set publish to mainnet vs testnet
	:return: the `https://chain.so/api/v2/send_tx/` json response
	"""
	data = {'tx_hex': transaction}
	network = 'BTCTEST' if testnet else 'BTC'
	response = requests.post(f'https://chain.so/api/v2/send_tx/{network}', data=data)
	return response.json()