Assets
Money Button allows developers to create assets using the BSV blockchain by implementing different token protocols. In our terminology, we call "assets" to what is more commonly referred to as "tokens".
If you haven't already, take a look into our tokens section.
Let's see a full example of an app that allows its users to create assets and transfer tokens that will be shown in their Money Button account.
Request permissions
The first step will be to use our OAuth integration to sign-in your users, requesting the following permissions:
Scope | Description |
---|---|
users.asset:write | Allows to define a new asset |
users.asset:read | Allows to read all defined assets |
In addition to this asset-related scope, you'll probably want to
add other permissions like users.balance:read
to access the user's balances
(BSV and assets/tokens).
Follow the steps explained in OAuth with JS Client to complete the sign-in process.
Create an asset
To create an asset the user will need to complete two steps:
- Define the asset's properties
- Mint the tokens
Defining an asset
This first step just gives Money Button information about the asset that you want to create, without making any transaction or writing any information in the blockchain.
You can use our JS client to do this:
const client = new MoneyButtonClient('<OAUTH CLIENT IDENTIFIER>')
client
.createAsset(
'SFP', // Protocol to use
'My First Asset', // Asset name
1000 // Initial supply
).then(result => {
console.log(result.paymailAlias)
})
The JS client is using our Create Asset API endpoint.
After that call your user's asset will be defined and ready to be minted. Check our supported protocols to see which protocols you may use.
After defining an asset you will receive a random "paymail alias" that will be used to identify this asset. This is what we will use to mint the tokens in the next step, and what will be used to perform transfers.
Minting tokens
To actually record the tokens in BSV blockchain, we need to perform a "minting" transaction. For this you can use our JS client to render a button that will be used to create and send that transaction.
const client = new MoneyButtonClient('<OAUTH CLIENT IDENTIFIER>')
client
.createAsset(
'SFP', // Protocol to use
'My First Asset', // Asset name
1000 // Initial supply
).then(result => {
// Render a button to mint the tokens
moneyButton.render(document.getElementById('mb-button'), {
outputs: [
{
asset: result.paymailAlias + "@moneybutton.com",
amount: result.initialSupply,
}
]
})
})
In this example, once the asset is defined, the button will be rendered
so the user can swipe and send the minting transaction. As you can see there's
no address
field since the user will receive all the minted tokens.
Transfer an asset
When a user has a particular asset you can use the asset's paymail to render buttons that can transfer them:
moneyButton.render(document.getElementById('mb-button'), {
outputs: [
{
to: "rob@moneybutton.com",
asset: "73ade9edf94b.asset@moneybutton.com",
amount: 150,
}
]
})
With these two examples you can create an app that creates tokens and allows your users to transfer them by simply swiping, just as they do to transfer BSV.