Skip to main content


On BandChain, a data source can be registered into the system by anyone. This is done through the registrant sending a MsgCreateDataSource message to the chain.

A MsgCreateDataSource message contains various parameters of the data source that is to be registered. These parameters include:

  • name: Name of the data source.
  • description: A description of the data source .
  • executable: Contents of the executable to be run by block validators upon receiving a data request for this data source.
  • fee: A stipulated per-query fee that those who use this data source are required to pay.
  • treasury: A treasury address of which the stipulated fee is to be paid to.
  • owner: The owner address of this data source. The owner will have edit rights. If omitted, the data source parameters will no longer be able to be edited after being registered.
  • sender: The message sender account.

In order to send a MsgCreateDataSource message, we can use either bandchain.js or pyband

An example on how to send a MsgCreateDataSource message via BandChain.js can be seen below.

import { Client, Wallet, Message, Coin, Transaction, Fee } from '@bandprotocol/bandchain.js'
import fs from 'fs'
import path from 'path'

// Setup the client
const grpcURL = ''
const client = new Client(grpcURL)

async function createDataSource() {
// Setup the wallet
const { PrivateKey } = Wallet
const mnemonic = process.env.MNEMONIC
const privateKey = PrivateKey.fromMnemonic(mnemonic)
const publicKey = privateKey.toPubkey()
const sender = publicKey.toAddress().toAccBech32()

// Setup the transaction's properties
const chainId = await client.getChainId()
const execPath = path.resolve(__dirname, '')
const file = fs.readFileSync(execPath, 'utf8')
const executable = Buffer.from(file).toString('base64')

let feeCoin = new Coin()

const requestMessage = new Message.MsgCreateDataSource(
'Hello World!', // Data source name
executable, // Data source executable
sender, // Treasury address
sender, // Owner address
sender, // Sender address
[feeCoin], // Fee
'' // Data source description

// Construct the transaction
const fee = new Fee()

const txn = new Transaction()
await txn.withSender(client, sender)

// Sign the transaction
const signDoc = txn.getSignDoc(publicKey)
const signature = privateKey.sign(signDoc)
const txRawBytes = txn.getTxData(signature, publicKey)

// Broadcast the transaction
const sendTx = await client.sendTxBlockMode(txRawBytes)

return sendTx

;(async () => {
console.log(await createDataSource())

An example on how to send a MsgCreateDataSource message via pyband can also be seen below.

import os

from pyband import Client, Transaction
from pyband.wallet import PrivateKey
from pyband.proto.cosmos.base.v1beta1.coin_pb2 import Coin
from import MsgCreateDataSource
from google.protobuf.json_format import MessageToJson

def main():
# Setup the client
grpc_url = ""
c = Client(grpc_url)

# Setup the wallet
mnemonic = os.getenv("MNEMONIC")
private_key = PrivateKey.from_mnemonic(mnemonic)
public_key = private_key.to_public_key()
sender_addr = public_key.to_address()
sender = sender_addr.to_acc_bech32()

# Prepare the transaction's properties
deploy_msg = MsgCreateDataSource(
name="Hello World!",
executable=open("", "rb").read(),
fee=[Coin(amount="0", denom="uband")],

account = c.get_account(sender)
account_num = account.account_number
sequence = account.sequence

fee = [Coin(amount="50000", denom="uband")]
chain_id = c.get_chain_id()

# Construct the transaction
txn = (

# Sign the Transaction
sign_doc = txn.get_sign_doc(public_key)
signature = private_key.sign(sign_doc.SerializeToString())
tx_raw_bytes = txn.get_tx_data(signature, public_key)

# Broadcast the transaction
tx_block = c.send_tx_block_mode(bytes(tx_raw_bytes))


if __name__ == "__main__":

After the transaction is successfully broadcasted. The newly created data source ID can be found in the response json. The registrant can also view the created data source details on CosmoScan. An example of a successful transaction will return a response similar to the one shown below.

"height": "7232244",
"txhash": "B7A039E4AE9567A7380B5241B72FF69D38DB6831BE5023F05140616AD71FFA62",
"data": "0A200A1E2F6F7261636C652E76312E4D736743726561746544617461536F75726365",
"rawLog": "[{\"events\":[{\"type\":\"create_data_source\",\"attributes\":[{\"key\":\"id\",\"value\":\"327\"}]},{\"type\":\"message\",\"attributes\":[{\"key\":\"action\",\"value\":\"/oracle.v1.MsgCreateDataSource\"}]}]}]",
"logs": [
"events": [
"type": "create_data_source",
"attributes": [
"key": "id",
"value": "327"
"type": "message",
"attributes": [
"key": "action",
"value": "/oracle.v1.MsgCreateDataSource"
"gasWanted": "100000",
"gasUsed": "55306"