Build your own player on SHARE
SHARE is a protocol for decentralized music and video distribution on blockchain. You can build your own music apps on SHARE and save time by leveraging existing payments tech, onchain smart contracts and user interface software. For in depth background please review the SHARE whitepaper: https://formless-eng.s3.us-east-2.amazonaws.com/share+whitepaper+7.pdf A working open source player that you can copy, modify and fork for your own applications under the MIT license is available here: https://github.com/formless-eng/share-v1-player
PFA Smart Contracts
The primary building blocks of SHARE are Pay-For-Access (PFA) smart contracts. Every smart contract has an address and a network ID. On share.stream, this looks like https://share.stream/assets/base/0x4754FE39AFAE67F886088774A047607CC6CFA693, wherebase is the name of network 8453 (Coinbase) and 0x4754FE39AFAE67F886088774A047607CC6CFA693 is the PFA contract address.
In all examples, the network ID is 8453, which is the Base blockchain. PFAs allow applications to retrieve the following information for a given piece of content:
tokenURI function of the PFA on the blockchain, which returns a SHARE decentralized distribution network (DDN) endpoint mapping to the content, such as:
https://share-ddn-micro.formless.xyz/v1?contractAddress=0x8E77F3070A0973386AF4F4D1C38C3502DD811388&networkId=8453
For example, this endpoint returns the following:
collection array) automatically.
The following sections cover how to build a player app using the PFA building block.
Wallets and Balances
This guide uses the Privy wallet, which is owned by Stripe and recommended when building your applications on SHARE. Once your Privy project is set up, import Privy into your application to easily enable users to fund their digital wallets with Apple Pay, Google Pay, Credit Card, or Crypto (USDC stablecoins), to check their balances, and to make payments for PFAs. Payments on SHARE are done using USDC which is a stablecoin mapping to a digital dollar. All payments and splits are handled onchain for all stakeholders of a given piece of content. Your app does not need to handle that infrastructure. Uploads, payment splits, withdrawals etc. are handled by SHARE and artists have access to these capabilities in the main share.stream/dashboard dashboard. For your consumer facing player, you only need the PFA contract address to serve content to users. If you’d like to build a marketplace application, you can maintain your own database of PFA contract addresses. Here’s an example of reading a user’s USDC balance using Viem and a Privy wallet.Adding funds (USDC) to a user’s digital wallet
Getting the price of a PFA asset
SHARE Protocol is a smart contract on the Base blockchain at address0x3Fb4b0b61ADB6d33EE901690E2C87B413c30968b. To get the price of a PFA asset, we make a grossPricePerAccess function call on the SHARE protocol contract and supply the PFA contract address. The returned price is in USDC.
Purchasing access to a PFA
Purchasing access is done by calling a smart contractaccess function directly on the PFA. Note that this is fundamentally different from NFTs. In the case of NFTs, users are buying and selling an NFT itself. In SHARE, the PFA smart contract remains with the owner. Only a function call is being performed, and that function call routes payment to the rightful owners, enabling a consumer to obtain the content. There is no NFT exchanged in a content purchase. If the PFA were purchased in its entirety, it would be equivalent to a transfer of ownership of the entire PFA, not a purchase of access to its underlying content.
Getting the token URI from the PFA
PFAs adhere to the ERC721 standard meaning all PFAs have atokenURI function. This function is what can be called on the blockchain to obtain the example URL above (eg. https://share-ddn-micro.formless.xyz/v1?contractAddress=0x8E77F3070A0973386AF4F4D1C38C3502DD811388&networkId=8453 is the tokenURI for contract address 0x8E77F3070A0973386AF4F4D1C38C3502DD811388 on Base). The token URI can be requested over HTTP to get the content metadata (title, image, audio, video etc).
0 index is ever used when calling tokenURI on SHARE PFA smart contracts.
Authenticating Token URI Requests
Once a PFAs tokenURI is obtained, a signed message must be appended to it in order to access paid content. The signed message is always the signed string below. Signing can be done using Privy’s built in smart walletsignMessage capability.
