LogoLogo
  • 🚀getting started
    • Intro to Data Unions
    • Build a Data Union
      • 1️Installation And Deployment
      • 2️Integration
    • Build a Data Union with Streamr
      • 1️Create A Data Stream
      • 2️Deploy A Data Union With Streamr Core
      • 3️Integrate Data Union & Stream
      • 4️Publish to Streamr Marketplace
    • Glossary of Terms
  • 📚Main Concepts
    • Roles and Responsibilities
      • 🧑‍💻Admin
      • 🤵JoinPart Agents
      • 🙋Member
      • 🧑‍🔧Protocol Beneficiary
    • Join Server
    • Contract Functions
    • Manage Wallets And Earnings
    • Data Union Observation
    • Add Your Own Token
    • Custom Modules
  • 🧐Resources
    • Existing Data Unions
    • Framework Governance
    • Data Unions UX Best Practices
  • ❓Questions?
    • Ask us on Discord
Powered by GitBook
On this page
  • Member Joins
  • Withdraw Earnings

Was this helpful?

  1. getting started
  2. Build a Data Union

Integration

PreviousInstallation And DeploymentNextBuild a Data Union with Streamr

Last updated 2 years ago

Was this helpful?

Member Joins

Add members manually as the :

Make sure this is just a script and not your actual application. You don't want the Data Union client to be configured with the admins private key in your client application.

const PRIVATE_KEY_ADMIN = process.env.PRIVATE_KEY;
// Paste the contract address of your newly created data union
const DU_CONTRACT_ADDRESS = "0x0D483E10612F327FC11965Fc82E90dC19b141641"

const DU = new DataUnionClient({
  auth: {
    privateKey: PRIVATE_KEY,
  },
  chain: 'polygon',
});

const dataUnion = await DU.getDataUnion(DU_CONTRACT_ADDRESS);
const tx = await dataUnion.addMembers(['0xabcd', "0x1234"]);

Or let members join themselves via our default :

Your script:
const PRIVATE_KEY_ADMIN = process.env.PRIVATE_KEY;
// Paste the contract address of your newly created data union
const DU_CONTRACT_ADDRESS = "0x0D483E10612F327FC11965Fc82E90dC19b141641"

const DU = new DataUnionClient({
  auth: {
    privateKey: PRIVATE_KEY_ADMIN,
  },
  chain: 'polygon',
});

const dataUnion = await DU.getDataUnion(
    DATA_UNION_CONTRACT_ADDRESS
);

// returns an object with:
// your secret, secret_name, data union contract address and the chain
const sharedSecret = dataUnion.createSecret($custum_secret_name);
In your client app
// get your clients wallet
const WALLET_PROVIDER = // walletProviderOfYourChoice;
// Paste the contract address of your newly created data union
const DU_CONTRACT_ADDRESS = "0x0D483E10612F327FC11965Fc82E90dC19b141641";
const SHARED_SECRET = process.env.SHARED_SECRET;

const DU = new DataUnionClient({
  auth: WALLET_PROVIDER,
  chain: 'polygon',
});

const dataUnion = await DU.getDataUnion(
    DATA_UNION_CONTRACT_ADDRESS
);
const joinResponse = dataUnion.join({secret: SHARED_SECRET});

Withdraw Earnings

After this transaction your users will be able to see and withdraw their earnings. With every withdraw transaction the revenue will get refreshed automatically.

In your client app
// get your clients wallet
const WALLET_PROVIDER = // walletProviderOfYourChoice;
// Paste the contract address of your newly created data union
const DU_CONTRACT_ADDRESS = "0x0D483E10612F327FC11965Fc82E90dC19b141641";

const DU = new DataUnionClient({
  auth: {
    WALLET_PROVIDER
  },
  chain: 'polygon',
});

const dataUnion = await DU.getDataUnion(DU_CONTRACT_ADDRESS);

const earnings = await dataUnion.getWithdrawableEarnings(
      '0x008ef9bB0d80829ea82e53fFE40F35B4eaDd1319'
);
const tx = await dataUnion.withdrawAll()

When the contract receives revenue in DATA token you need to refresh the contract manually with the contract function refreshRevenue(). The will do this automatically for you.

🚀
2️
joinPart agent
join server
Streamr marketplace