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 keyin yourclient application.
constPRIVATE_KEY_ADMIN=process.env.PRIVATE_KEY;// Paste the contract address of your newly created data unionconstDU_CONTRACT_ADDRESS="0x0D483E10612F327FC11965Fc82E90dC19b141641"constDU=newDataUnionClient({ auth: { privateKey:PRIVATE_KEY, }, chain:'polygon',});constdataUnion=awaitDU.getDataUnion(DU_CONTRACT_ADDRESS);consttx=awaitdataUnion.addMembers(['0xabcd',"0x1234"]);
Or let members join themselves via our default join server:
Your script:
constPRIVATE_KEY_ADMIN=process.env.PRIVATE_KEY;// Paste the contract address of your newly created data unionconstDU_CONTRACT_ADDRESS="0x0D483E10612F327FC11965Fc82E90dC19b141641"constDU=newDataUnionClient({ auth: { privateKey:PRIVATE_KEY_ADMIN, }, chain:'polygon',});constdataUnion=awaitDU.getDataUnion(DATA_UNION_CONTRACT_ADDRESS);// returns an object with:// your secret, secret_name, data union contract address and the chainconstsharedSecret=dataUnion.createSecret($custum_secret_name);
In your client app
// get your clients walletconstWALLET_PROVIDER=// walletProviderOfYourChoice;// Paste the contract address of your newly created data unionconstDU_CONTRACT_ADDRESS="0x0D483E10612F327FC11965Fc82E90dC19b141641";constSHARED_SECRET=process.env.SHARED_SECRET;constDU=newDataUnionClient({ auth:WALLET_PROVIDER, chain:'polygon',});constdataUnion=awaitDU.getDataUnion(DATA_UNION_CONTRACT_ADDRESS);constjoinResponse=dataUnion.join({secret:SHARED_SECRET});
Withdraw Earnings
When the contract receives revenue in DATA token you need to refresh the contract manually with the contract function refreshRevenue(). The Streamr marketplace will do this automatically for you.
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 walletconstWALLET_PROVIDER=// walletProviderOfYourChoice;// Paste the contract address of your newly created data unionconstDU_CONTRACT_ADDRESS="0x0D483E10612F327FC11965Fc82E90dC19b141641";constDU=newDataUnionClient({ auth: { WALLET_PROVIDER }, chain:'polygon',});constdataUnion=awaitDU.getDataUnion(DU_CONTRACT_ADDRESS);constearnings=awaitdataUnion.getWithdrawableEarnings('0x008ef9bB0d80829ea82e53fFE40F35B4eaDd1319');consttx=awaitdataUnion.withdrawAll()