31 Oct 2024

feedStories by BitTorrent Inc. on Medium

BTFS Protocol v3.1.0 Mainnet Is Now Live!

This update enhances protocol security, with key improvements outlined below:

  1. Added password verification to Dashboard: This offers users stronger protection, further securing data access.
  2. Removed retired and rarely-used features: This streamlines user experience and boosts system performance.

We're always pushing the boundaries to make the BTFS protocol better, fueling the future of decentralized networks. Got questions or ideas? We'd love to hear from you - reach out anytime!

Helpful links for BTFS v3.1.0 Mainnet:

● GitHub repo for BTFS v3.1.0 Mainnet: https://github.com/bittorrent/go-btfs/releases/tag/btfs-v3.1.0

● BTFS Dashboard repo: https://github.com/bittorrent/btfs-dashboard

● BTFS official website: https://www.btfs.io

● BTFS SCAN: https://www.btfs.io

● BTFS documentation: https://docs.btfs.io/docs

Contact us

Have any questions or want to engage with fellow BTFS users? Connect with us and be part of the community:

● Discord: https://discord.gg/tJ4fz6C6rw

● Medium: https://medium.com/@BitTorrent

● X (formerly Twitter): https://twitter.com/BitTorrent

About BTFS

The BitTorrent File System (BTFS) is both a protocol and a web application that provides a content-addressable peer-to-peer mechanism for storing and sharing digital content in a decentralized file system, as well as a base platform for decentralized applications (Dapp). The BTFS team has been working on the latest network operations and BTT market sentiment, etc., to make a series of dynamic adjustments such as upload prices and airdrop reward schemes.

31 Oct 2024 11:22am GMT

29 Oct 2024

feedStories by BitTorrent Inc. on Medium

BitTorrent Weekly Report | 10.21–10.27

Founded with a leading peer-to-peer sharing technology standard in 2004, BitTorrent, Inc. is a consumer software company based in San Francisco. Its protocol is the largest decentralized P2P network in the world, driving 22% of upstream and 3% of downstream traffic globally.

Its flagship desktop and mobile products, BitTorrent and µTorrent, enable users to send large files over the internet, connecting legitimate third-party content providers with users. With over 100 million active users, BitTorrent products have been installed on over 1 billion devices in over 138 countries worldwide.

Since November 2018, TRON (TRX), Binance (BNB), and Bitcoin (BTC) holders have the opportunity to purchase one-year subscriptions of BitTorrent or µTorrent products, including Ads Free and Pro for Windows. Pro includes anti-virus and anti-malware screening, file converting and playability in HD. Users can visit bittorrent.com or utorrent.com to learn more.

29 Oct 2024 9:38am GMT

22 Oct 2024

feedStories by BitTorrent Inc. on Medium

BitTorrent Weekly Report | 10.14–10.20

Founded with a leading peer-to-peer sharing technology standard in 2004, BitTorrent, Inc. is a consumer software company based in San Francisco. Its protocol is the largest decentralized P2P network in the world, driving 22% of upstream and 3% of downstream traffic globally.

Its flagship desktop and mobile products, BitTorrent and µTorrent, enable users to send large files over the internet, connecting legitimate third-party content providers with users. With over 100 million active users, BitTorrent products have been installed on over 1 billion devices in over 138 countries worldwide.

Since November 2018, TRON (TRX), Binance (BNB), and Bitcoin (BTC) holders have the opportunity to purchase one-year subscriptions of BitTorrent or µTorrent products, including Ads Free and Pro for Windows. Pro includes anti-virus and anti-malware screening, file converting and playability in HD. Users can visit bittorrent.com or utorrent.com to learn more.

22 Oct 2024 7:51am GMT

15 Oct 2024

feedStories by BitTorrent Inc. on Medium

BitTorrent Weekly Report | 10.07–10.13

Founded with a leading peer-to-peer sharing technology standard in 2004, BitTorrent, Inc. is a consumer software company based in San Francisco. Its protocol is the largest decentralized P2P network in the world, driving 22% of upstream and 3% of downstream traffic globally.

Its flagship desktop and mobile products, BitTorrent and µTorrent, enable users to send large files over the internet, connecting legitimate third-party content providers with users. With over 100 million active users, BitTorrent products have been installed on over 1 billion devices in over 138 countries worldwide.

Since November 2018, TRON (TRX), Binance (BNB), and Bitcoin (BTC) holders have the opportunity to purchase one-year subscriptions of BitTorrent or µTorrent products, including Ads Free and Pro for Windows. Pro includes anti-virus and anti-malware screening, file converting and playability in HD. Users can visit bittorrent.com or utorrent.com to learn more.

15 Oct 2024 10:42am GMT

08 Oct 2024

feedStories by BitTorrent Inc. on Medium

BitTorrent Weekly Report | 09.30–10.06

Founded with a leading peer-to-peer sharing technology standard in 2004, BitTorrent, Inc. is a consumer software company based in San Francisco. Its protocol is the largest decentralized P2P network in the world, driving 22% of upstream and 3% of downstream traffic globally.

Its flagship desktop and mobile products, BitTorrent and µTorrent, enable users to send large files over the internet, connecting legitimate third-party content providers with users. With over 100 million active users, BitTorrent products have been installed on over 1 billion devices in over 138 countries worldwide.

Since November 2018, TRON (TRX), Binance (BNB), and Bitcoin (BTC) holders have the opportunity to purchase one-year subscriptions of BitTorrent or µTorrent products, including Ads Free and Pro for Windows. Pro includes anti-virus and anti-malware screening, file converting and playability in HD. Users can visit bittorrent.com or utorrent.com to learn more.

08 Oct 2024 7:15am GMT

02 Oct 2024

feedStories by BitTorrent Inc. on Medium

Revolutionizing Crowdfunding: Exploring the CrowdFunding Smart Contract on BTTC

Welcome, blockchain enthusiasts and crowdfunding revolutionaries! Today, we're diving deep into a smart contract that's set to transform the way we fund great ideas - the CrowdFunding contract on BitTorrent Chain (BTTC). This powerful piece of code brings transparency, efficiency, and trust to the world of crowdfunding. Let's unpack this digital marvel and see how it works!

The CrowdFunding Contract: Your Decentralized Fundraising Platform

Imagine a world where crowdfunding campaigns are transparent, secure, and free from intermediaries. That's exactly what our CrowdFunding contract achieves. It's a self-contained ecosystem for creating, managing, and contributing to fundraising campaigns on the blockchain.

State Variables and Structs: The Building Blocks

The contract starts by defining the essential variables and structures needed to manage crowdfunding campaigns:

// Address of the contract owner
address private immutable owner;

// Counter for generating campaign IDs
uint private nextId = 1;

// Array to store campaign information
Campaign[] public campaigns;

// Flag to prevent reentrant calls
bool private locked;

// Modifier to prevent reentrant calls
modifier nonReentrant() {
require(!locked, "Reentrant call");
locked = true;
_;
locked = false;
}

// Struct to define the structure of a crowdfunding campaign
struct Campaign {
uint id;
address campaignCreator;
string title;
string description;
string imageURI;
uint goal;
uint startsAt;
uint endsAt;
STATUS status;
uint totalContributions;
address[] contributors;
uint[] contributionAmounts;
}

// Enum representing the status of a campaign
enum STATUS {
ACTIVE,
DELETED,
SUCCESSFUL,
UNSUCCEEDED
}

These variables and structs form the backbone of our contract:

- owner: The address that deployed the contract.

- nextId: A counter for generating unique campaign IDs.

- campaigns: An array storing all campaign information.

- Campaign: A struct defining the structure of each crowdfunding campaign.

- STATUS: An enum representing the possible states of a campaign.

Events: Keeping Everyone Informed

Events are crucial for transparency and off-chain tracking:

// Events to log important activities
event CampaignCreated(uint indexed campaignId, address campaignCreator, string title, STATUS status);
event CampaignDeleted(uint indexed campaignId, address campaignCreator, STATUS status);
event ContributionMade(uint indexed campaignId, address contributor, uint amount);
event RefundMade(uint indexed campaignId, address contributor, uint amount);

These events help in tracking the lifecycle of campaigns and contributions:

- CampaignCreated: Fired when a new campaign is launched.

- CampaignDeleted: Emitted when a campaign is deleted.

- ContributionMade: Logs each contribution to a campaign.

- RefundMade: Records when a refund is processed.

Constructor: Initializing the Contract

The constructor sets the deployer of the contract as the owner, ensuring that only the owner can perform certain administrative actions:

constructor() {
owner = msg.sender;
}

Key Functions: The Heart of Crowdfunding

Creating a Campaign

This function allows anyone to create a new crowdfunding campaign:

function createCampaign(
string memory title,
string memory description,
string memory imageURI,
uint goal,
uint endsAt
) public {
// Validation checks for input parameters
require(bytes(title).length > 0, 'Title must not be empty');
require(bytes(description).length > 0, 'Description must not be empty');
require(bytes(imageURI).length > 0, 'Image URI must not be empty');
require(goal > 0, 'Goal must be greater than zero');
require(endsAt > block.timestamp, 'Ends time must be greater than the current time');

// Create a new campaign and add it to the array
campaigns.push(Campaign(
nextId++,
msg.sender,
title,
description,
imageURI,
goal,
block.timestamp,
endsAt,
STATUS.ACTIVE,
0,
new address[](0),
new uint[](0)
));

// Emit an event to log the creation of the campaign
emit CampaignCreated(nextId - 1, msg.sender, title, STATUS.ACTIVE);
}

Contributing to a Campaign

Here's where the magic happens! Contributors can send funds to support a campaign:

function contribute(uint campaignId) public payable nonReentrant {
// Retrieve the campaign based on the campaign ID
Campaign storage campaign = campaigns[campaignId];

// Validation check for contribution amount
require(msg.value > 0, 'Contribution amount must be greater than zero');

// Calculate the remaining funds needed to reach the campaign goal
uint remainingFundsNeeded = campaign.goal - campaign.totalContributions;

// Handle contributions based on the remaining funds needed
if (msg.value <= remainingFundsNeeded) {
campaign.totalContributions += msg.value;
} else {
// Handle excess contributions and refunds
uint excessAmount = msg.value - remainingFundsNeeded;
uint refundedAmount = msg.value - excessAmount;

// Refund the excess amount to the contributor
payable(msg.sender).transfer(excessAmount);

// Update the total contributions with the refunded amount
campaign.totalContributions += refundedAmount;

// Mark the campaign as successful if the goal is reached
if (campaign.totalContributions >= campaign.goal) {
campaign.status = STATUS.SUCCESSFUL;
}
}

// Record the contributor and contribution amount
campaign.contributors.push(msg.sender);
campaign.contributionAmounts.push(msg.value);

// Emit an event to log the contribution
emit ContributionMade(campaignId, msg.sender, msg.value);
}

Deleting a Campaign

Campaign creators can use this function to delete their campaigns:

function deleteCampaign(uint campaignId) public {
// Retrieve the campaign based on the campaign ID
Campaign storage campaign = campaigns[campaignId];

// Validation check: Only the campaign creator can delete the campaign
require(campaign.campaignCreator == msg.sender);

// Refund contributors when the campaign is deleted
refund(campaignId);

// Mark the campaign as deleted
campaign.status = STATUS.DELETED;

// Emit an event to log the deletion of the campaign
emit CampaignDeleted(campaignId, msg.sender, STATUS.DELETED);
}

Internal Refund Function

This internal function handles the refund process when a campaign is deleted:

function refund(uint campaignId) internal {
// Retrieve the campaign based on the campaign ID
Campaign storage campaign = campaigns[campaignId];

// Iterate through contributors and refund their contributions
for (uint i = 0; i < campaign.contributors.length; i++) {
address contributor = campaign.contributors[i];
uint contributionAmount = campaign.contributionAmounts[i];

// Refund the contribution amount to the contributor
payable(contributor).transfer(contributionAmount);

// Update the total contributions
campaign.totalContributions -= contributionAmount;

// Emit an event to log the refund
emit RefundMade(campaignId, contributor, contributionAmount);
}
}

Retrieving Campaign Information

These functions provide various ways to retrieve campaign information:

function getAllCampaigns() public view returns (Campaign[] memory) {
return campaigns;
}

function getCampaignDetails(uint campaignId) public view returns (
uint id,
address campaignCreator,
string memory title,
string memory description,
string memory imageURI,
uint goal,
uint startsAt,
uint endsAt,
STATUS status,
uint totalContributions,
address[] memory contributors,
uint[] memory contributionAmounts
) {
Campaign memory campaign = campaigns[campaignId];
return (
campaign.id,
campaign.campaignCreator,
campaign.title,
campaign.description,
campaign.imageURI,
campaign.goal,
campaign.startsAt,
campaign.endsAt,
campaign.status,
campaign.totalContributions,
campaign.contributors,
campaign.contributionAmounts
);
}

function getTotalContributions(uint campaignId) public view returns (uint) {
return campaigns[campaignId].totalContributions;
}

function getLatestCampaigns() public view returns (Campaign[] memory) {
require(campaigns.length > 0, "No campaigns found.");

// Determine the start index based on the number of campaigns
uint startIndex = campaigns.length > 4 ? campaigns.length - 4 : 0;
uint latestCampaignsCount = campaigns.length - startIndex;

// Create an array for the latest campaigns
Campaign[] memory latestCampaigns = new Campaign[](latestCampaignsCount);

// Populate the array with the latest campaigns
for (uint i = 0; i < latestCampaignsCount; i++) {
latestCampaigns[i] = campaigns[campaigns.length - 1 - i];
}

return latestCampaigns;
}

Beyond the Basics: The Power of Decentralized Crowdfunding

This CrowdFunding contract opens up a world of possibilities:

Conclusion: Funding the Future, One Block at a Time

The CrowdFunding smart contract is more than just code

- it's a glimpse into the future of fundraising. By leveraging blockchain technology, we're creating a more transparent, efficient, and accessible crowdfunding ecosystem.

As you explore the potential of this contract on BTTC, remember: you're not just participating in campaigns, you're pioneering a new era of decentralized finance and community support.

So, what groundbreaking idea will you fund first? The blockchain is waiting, and the crowd is ready to back the next big thing!

Github URL:
https://github.com/adeelch9/bttc-examples/tree/master/projects/crowdfunding

Bonus Section: Diving Deeper into BTTC Smart Contracts

We've only scratched the surface of what's possible with smart contracts on the BitTorrent Chain. For those eager to take their blockchain development skills to the next level, we've got a treasure trove of resources waiting for you in our GitHub repository!

🚀 Explore the Full Project

Head over to our BTTC Examples GitHub Repository to discover a wealth of additional content and features:

  1. Complete Contract Code: While we've covered the main functions, the repository contains the full smart contract code, including any methods we didn't have space to discuss here.
  2. Deployment Scripts: Ever wondered how to deploy your smart contracts to the BTTC network? We've got you covered with ready-to-use deployment scripts that make the process a breeze.
  3. Comprehensive Tests: Writing tests for smart contracts is crucial for ensuring their reliability and security. Our repository includes a suite of tests that demonstrate best practices in smart contract testing.
  4. Multiple Projects: Beyond the contract we've discussed today, you'll find a variety of other smart contract examples, from simple to advanced, showcasing different aspects of blockchain development on BTTC.
  5. Documentation: Detailed README files and inline comments provide additional context and explanations, making it easier to understand and modify the code for your own projects.

🛠️ Getting Started

To make the most of these resources:

  1. Clone the repository: git clone https://github.com/adeelch9/bttc-examples.git
  2. Navigate to the project directory of your choice
  3. Follow the setup instructions in the project's README
  4. Experiment with the contracts, run tests, and try deploying to a testnet

🌟 Why This Matters

By exploring the full repository, you'll gain:

- A deeper understanding of smart contract development

- Hands-on experience with deployment and testing

- Exposure to best practices in blockchain development

- Inspiration for your own BTTC projects

Whether you're a beginner looking to learn or an experienced developer seeking to refine your skills, our BTTC Examples repository is your gateway to mastering smart contract development on the BitTorrent Chain.

Happy coding, and may your blockchain journey be filled with innovation and success.

02 Oct 2024 4:30am GMT

01 Oct 2024

feedStories by BitTorrent Inc. on Medium

BitTorrent Weekly Report | 09.23–09.29

Founded with a leading peer-to-peer sharing technology standard in 2004, BitTorrent, Inc. is a consumer software company based in San Francisco. Its protocol is the largest decentralized P2P network in the world, driving 22% of upstream and 3% of downstream traffic globally.

Its flagship desktop and mobile products, BitTorrent and µTorrent, enable users to send large files over the internet, connecting legitimate third-party content providers with users. With over 100 million active users, BitTorrent products have been installed on over 1 billion devices in over 138 countries worldwide.

Since November 2018, TRON (TRX), Binance (BNB), and Bitcoin (BTC) holders have the opportunity to purchase one-year subscriptions of BitTorrent or µTorrent products, including Ads Free and Pro for Windows. Pro includes anti-virus and anti-malware screening, file converting and playability in HD. Users can visit bittorrent.com or utorrent.com to learn more.

01 Oct 2024 3:10am GMT

25 Sep 2024

feedStories by BitTorrent Inc. on Medium

Unlocking the Future: Exploring the StakingRewards Contract on BTTC

Welcome, blockchain enthusiasts and crypto innovators! Today, we're diving into a powerful smart contract that brings token staking and rewards to the BitTorrent Chain (BTTC) - the StakingRewards contract. This contract allows users to stake tokens and earn rewards over time, creating a decentralized and automated way to incentivize participation. Let's break down the key components and functionalities of this contract.

The StakingRewards Contract: Your Gateway to Passive Income

Imagine a smart contract that allows you to stake your tokens and earn rewards over a specified period. That's exactly what our StakingRewards contract does. It's perfect for creating incentive mechanisms and encouraging long-term participation in your token ecosystem.

State Variables and Structs: The Foundation

IERC20 public immutable stakingToken;
IERC20 public immutable rewardsToken;

address public owner;

// Duration of rewards to be paid out (in seconds)
uint public duration;
// Timestamp of when the rewards finish
uint public finishAt;
// Minimum of last updated time and reward finish time
uint public updatedAt;
// Reward to be paid out per second
uint public rewardRate;
// Sum of (reward rate * dt * 1e18 / total supply)
uint public rewardPerTokenStored;
// User address => rewardPerTokenStored
mapping(address => uint) public userRewardPerTokenPaid;
// User address => rewards to be claimed
mapping(address => uint) public rewards;

// Total staked
uint public totalSupply;
// User address => staked amount
mapping(address => uint) public balanceOf;

These variables form the backbone of our contract, defining the staking and reward mechanisms.

Events: Keeping Everyone Informed

While the contract doesn't explicitly define events in the provided code, it's a good practice to include them for transparency and off-chain tracking. Here are some suggested events:

event Staked(address indexed user, uint amount);
event Withdrawn(address indexed user, uint amount);
event RewardPaid(address indexed user, uint reward);
event RewardDurationUpdated(uint newDuration);
event RewardNotified(uint amount);

Key Functions: The Heart of Staking and Rewards

Constructor

constructor(address _stakingToken, address _rewardToken) {
owner = msg.sender;
stakingToken = IERC20(_stakingToken);
rewardsToken = IERC20(_rewardToken);
}

The constructor initializes the contract with the addresses of the staking and reward tokens, and sets the contract deployer as the owner.

Modifiers

modifier onlyOwner() {
require(msg.sender == owner, "not authorized");
_;
}

modifier updateReward(address _account) {
rewardPerTokenStored = rewardPerToken();
updatedAt = lastTimeRewardApplicable();

if (_account != address(0)) {
rewards[_account] = earned(_account);
userRewardPerTokenPaid[_account] = rewardPerTokenStored;
}

_;
}

These modifiers ensure that only the owner can perform certain actions and that rewards are updated before any state changes.

Reward Calculation Functions

function lastTimeRewardApplicable() public view returns (uint) {
return _min(finishAt, block.timestamp);
}

function rewardPerToken() public view returns (uint) {
if (totalSupply == 0) {
return rewardPerTokenStored;
}
return
rewardPerTokenStored +
(rewardRate * (lastTimeRewardApplicable() - updatedAt) * 1e18) /
totalSupply;
}

These functions calculate the last time rewards were applicable and the reward rate per token.

Staking and Withdrawing Tokens

function stake(uint _amount) external updateReward(msg.sender) {
require(_amount > 0, "amount = 0");
stakingToken.transferFrom(msg.sender, address(this), _amount);
balanceOf[msg.sender] += _amount;
totalSupply += _amount;
emit Staked(msg.sender, _amount);
}

function withdraw(uint _amount) external updateReward(msg.sender) {
require(_amount > 0, "amount = 0");
balanceOf[msg.sender] -= _amount;
totalSupply -= _amount;
stakingToken.transfer(msg.sender, _amount);
emit Withdrawn(msg.sender, _amount);
}

These functions allow users to stake and withdraw tokens, updating their rewards accordingly.

Earning and Claiming Rewards

function earned(address _account) public view returns (uint) {
return
((balanceOf[_account] *
(rewardPerToken() - userRewardPerTokenPaid[_account])) / 1e18) +
rewards[_account];
}

function getReward() external updateReward(msg.sender) {
uint reward = rewards[msg.sender];
if (reward > 0) {
rewards[msg.sender] = 0;
rewardsToken.transfer(msg.sender, reward);
emit RewardPaid(msg.sender, reward);
}
}

These functions calculate the rewards earned by a user and allow them to claim their rewards.

Setting Reward Parameters

function setRewardsDuration(uint _duration) external onlyOwner {
require(finishAt < block.timestamp, "reward duration not finished");
duration = _duration;
emit RewardDurationUpdated(_duration);
}

function notifyRewardAmount(uint _amount) external onlyOwner updateReward(address(0)) {
if (block.timestamp >= finishAt) {
rewardRate = _amount / duration;
} else {
uint remainingRewards = (finishAt - block.timestamp) * rewardRate;
rewardRate = (_amount + remainingRewards) / duration;
}

require(rewardRate > 0, "reward rate = 0");
require(
rewardRate * duration <= rewardsToken.balanceOf(address(this)),
"reward amount > balance"
);

finishAt = block.timestamp + duration;
updatedAt = block.timestamp;
emit RewardNotified(_amount);
}

These functions allow the owner to set the reward duration and notify the contract of the reward amount.

Utility Functions

function _min(uint x, uint y) private pure returns (uint) {
return x <= y ? x : y;
}

This utility function returns the minimum of two values.

Beyond the Basics: The Power of Decentralized Staking

This StakingRewards contract offers several advantages:

Conclusion: Unlocking the Future of Staking

The StakingRewards smart contract is more than just code - it's a gateway to passive income and decentralized finance. By leveraging blockchain technology, we're creating a more transparent, efficient, and accessible staking ecosystem.

As you explore the potential of this contract on BTTC, remember: you're not just staking tokens, you're pioneering a new era of decentralized finance and community participation.

So, what will you stake first? The blockchain is waiting, and the rewards are ready to be claimed!

Happy staking, and may your rewards be plentiful!

Github URL:
https://github.com/adeelch9/bttc-examples/tree/master/projects/staking-contract

Bonus Section: Diving Deeper into BTTC Smart Contracts

We've only scratched the surface of what's possible with smart contracts on the BitTorrent Chain. For those eager to take their blockchain development skills to the next level, we've got a treasure trove of resources waiting for you in our GitHub repository!

🚀 Explore the Full Project

Head over to our BTTC Examples GitHub Repository to discover a wealth of additional content and features:

  1. Complete Contract Code: While we've covered the main functions, the repository contains the full smart contract code, including any methods we didn't have space to discuss here.
  2. Deployment Scripts: Ever wondered how to deploy your smart contracts to the BTTC network? We've got you covered with ready-to-use deployment scripts that make the process a breeze.
  3. Comprehensive Tests: Writing tests for smart contracts is crucial for ensuring their reliability and security. Our repository includes a suite of tests that demonstrate best practices in smart contract testing.
  4. Multiple Projects: Beyond the contract we've discussed today, you'll find a variety of other smart contract examples, from simple to advanced, showcasing different aspects of blockchain development on BTTC.
  5. Documentation: Detailed README files and inline comments provide additional context and explanations, making it easier to understand and modify the code for your own projects.

🛠️ Getting Started

To make the most of these resources:

  1. Clone the repository: git clone https://github.com/adeelch9/bttc-examples.git
  2. Navigate to the project directory of your choice
  3. Follow the setup instructions in the project's README
  4. Experiment with the contracts, run tests, and try deploying to a testnet

🌟 Why This Matters

By exploring the full repository, you'll gain:

- A deeper understanding of smart contract development

- Hands-on experience with deployment and testing

- Exposure to best practices in blockchain development

- Inspiration for your own BTTC projects

Whether you're a beginner looking to learn or an experienced developer seeking to refine your skills, our BTTC Examples repository is your gateway to mastering smart contract development on the BitTorrent Chain.

Happy coding, and may your blockchain journey be filled with innovation and success.

25 Sep 2024 6:21am GMT

24 Sep 2024

feedStories by BitTorrent Inc. on Medium

BitTorrent Weekly Report | 09.16–09.22

Founded with a leading peer-to-peer sharing technology standard in 2004, BitTorrent, Inc. is a consumer software company based in San Francisco. Its protocol is the largest decentralized P2P network in the world, driving 22% of upstream and 3% of downstream traffic globally.

Its flagship desktop and mobile products, BitTorrent and µTorrent, enable users to send large files over the internet, connecting legitimate third-party content providers with users. With over 100 million active users, BitTorrent products have been installed on over 1 billion devices in over 138 countries worldwide.

Since November 2018, TRON (TRX), Binance (BNB), and Bitcoin (BTC) holders have the opportunity to purchase one-year subscriptions of BitTorrent or µTorrent products, including Ads Free and Pro for Windows. Pro includes anti-virus and anti-malware screening, file converting and playability in HD. Users can visit bittorrent.com or utorrent.com to learn more.

24 Sep 2024 7:52am GMT

18 Sep 2024

feedStories by BitTorrent Inc. on Medium

Decentralized Decision Making: Exploring VendingMachine and SimpleDAO Contracts

In the world of blockchain and smart contracts, we're witnessing innovative applications that reshape how we handle automated transactions and collective decision-making. Today, we'll dive deep into two fascinating smart contracts: VendingMachine and SimpleDAO (Decentralized Autonomous Organization).

The VendingMachine Contract: Automating Digital Purchases

Let's start with the VendingMachine contract, which simulates a digital vending machine on the blockchain:

contract VendingMachine {
address public owner;
mapping (address => uint) public cupcakeBalances;

constructor() {
owner = msg.sender;
cupcakeBalances[address(this)] = 100;
}

function refill(uint amount) public {
require(msg.sender == owner, "Only the owner can refill.");
cupcakeBalances[address(this)] += amount;
}

function purchase(uint amount) public payable {
require(msg.value >= amount * 1 ether, "You must pay at least 1 ETH per cupcake");
require(cupcakeBalances[address(this)] >= amount, "Not enough cupcakes in stock to complete this purchase");
cupcakeBalances[address(this)] -= amount;
cupcakeBalances[msg.sender] += amount;
}
}

This contract offers the following functionality:

  1. Initialization: The constructor sets up the vending machine with 100 cupcakes and designates the deployer as the owner.
  2. Refill Function: Only the owner can add more cupcakes to the machine.
  3. Purchase Function: Anyone can buy cupcakes by sending Ether, with each cupcake costing 1 ETH.
  4. Balance Tracking: The contract keeps track of cupcake balances for each address that interacts with it.

The SimpleDAO Contract: Decentralized Decision Making

Now, let's explore the SimpleDAO contract, which implements a basic decentralized autonomous organization:

contract SimpleDAO {
address payable public VendingMachineAddress;
uint public voteEndTime;
uint public DAObalance;
mapping(address=>uint) balances;
uint public decision;
bool public ended;

struct Voter {
uint weight;
bool voted;
address delegate;
uint vote;
}

struct Proposal {
string name;
uint voteCount;
}

address public chairperson;
mapping(address => Voter) public voters;
Proposal[] public proposals;

constructor(
address payable _VendingMachineAddress,
uint _voteTime,
string[] memory proposalNames
) {
VendingMachineAddress = _VendingMachineAddress;
chairperson = msg.sender;
voteEndTime = block.timestamp + _voteTime;
voters[chairperson].weight = 1;

for (uint i = 0; i < proposalNames.length; i++) {
proposals.push(Proposal({
name: proposalNames[i],
voteCount: 0
}));
}
}

function DepositEth() public payable {
DAObalance = address(this).balance;
require(DAObalance <= 1 ether, "1 Ether balance has been reached");
balances[msg.sender]+=msg.value;
}

function giveRightToVote(address voter) public {
require(msg.sender == chairperson, "Only chairperson can give right to vote.");
require(!voters[voter].voted, "The voter already voted.");
require(voters[voter].weight == 0);
voters[voter].weight = 1;
}

function vote(uint proposal) public {
Voter storage sender = voters[msg.sender];
require(sender.weight != 0, "Has no right to vote");
require(!sender.voted, "Already voted.");
sender.voted = true;
sender.vote = proposal;
proposals[proposal].voteCount += sender.weight;
}

function countVote() public returns (uint winningProposal_) {
require(block.timestamp > voteEndTime, "Vote not yet ended.");
uint winningVoteCount = 0;
for (uint p = 0; p < proposals.length; p++) {
if (proposals[p].voteCount > winningVoteCount) {
winningVoteCount = proposals[p].voteCount;
winningProposal_ = p;
decision = winningProposal_;
ended = true;
}
}
}

function withdraw(uint amount) public {
require(balances[msg.sender] >= amount, "amount > balance");
balances[msg.sender]-= amount;
payable(msg.sender).transfer(amount);
DAObalance = address(this).balance;
}

function EndVote() public {
require(block.timestamp > voteEndTime, "Vote not yet ended.");
require(ended == true, "Must count vote first");
require(DAObalance >= 1 ether, "Not enough balance in DAO required to buy cupcake. Members may withdraw deposited ether.");
require(decision == 0, "DAO decided to not buy cupcakes. Members may withdraw deposited ether.");

if (DAObalance < 1 ether) revert();
(bool success, ) = address(VendingMachineAddress).call{value: 1 ether}(abi.encodeWithSignature("purchase(uint256)", 1));
require(success);

DAObalance = address(this).balance;
}

function checkCupCakeBalance() public view returns (uint) {
VendingMachine vendingMachine = VendingMachine(VendingMachineAddress);
return vendingMachine.cupcakeBalances(address(this));
}
}

This DAO contract provides the following functionality:

  1. Initialization: The constructor sets up the DAO with a vending machine address, voting duration, and proposal options.
  2. Deposit Function: Members can deposit Ether into the DAO (up to a total of 1 ETH).
  3. Voting Rights: The chairperson can grant voting rights to members.
  4. Voting: Members can cast their votes for their preferred proposal.
  5. Vote Counting: After the voting period, votes are tallied to determine the winning proposal.
  6. Withdrawal: Members can withdraw their deposited Ether, subject to certain conditions.
  7. End Vote: Finalizes the voting process and executes the decision if the vote is to buy cupcakes.
  8. Check Cupcake Balance: Allows checking the DAO's cupcake balance in the vending machine.

How These Contracts Work Together

  1. Deploy the VendingMachine contract.
  2. Deploy the SimpleDAO contract, passing the VendingMachine address, voting duration, and proposal options.
  3. DAO members deposit Ether using the DepositEth function.
  4. The chairperson grants voting rights using giveRightToVote.
  5. Members cast their votes using the vote function.
  6. After the voting period, anyone can call countVote to tally the results.
  7. If the vote passes to buy cupcakes, EndVote is called to purchase from the VendingMachine.
  8. Members can check the DAO's cupcake balance using checkCupCakeBalance.
  9. If the vote fails or there's not enough balance, members can withdraw their Ether using withdraw.

Key Takeaways

  1. Automated Transactions: The VendingMachine contract demonstrates how we can automate simple transactions without intermediaries.
  2. Decentralized Governance: The SimpleDAO contract illustrates how groups can make collective decisions and execute them automatically.
  3. Inter-Contract Interaction: The SimpleDAO's ability to interact with the VendingMachine shows how different smart contracts can work together.
  4. Transparency: All transactions and decisions are recorded on the blockchain, ensuring complete transparency.
  5. Programmable Money: These contracts show how cryptocurrency can be programmed to behave based on predefined rules and collective decisions.

Conclusion

The VendingMachine and SimpleDAO contracts provide a glimpse into the future of decentralized systems. They demonstrate how blockchain technology can automate transactions, facilitate group decision-making, and create interoperable systems of smart contracts.

As blockchain technology continues to evolve, we can expect to see more complex and innovative applications of these concepts. From decentralized marketplaces to large-scale DAOs governing significant resources, the potential applications are vast and exciting.

These contracts serve as a starting point for developers and enthusiasts to explore the possibilities of decentralized systems. They invite us to imagine a future where autonomous digital entities interact, make decisions, and conduct transactions without the need for traditional intermediaries.

The journey of blockchain technology is just beginning, and contracts like these are paving the way for a more decentralized, transparent, and automated future.

Github URL:
https://github.com/adeelch9/bttc-examples/tree/master/projects/dao

Bonus Section: Diving Deeper into BTTC Smart Contracts

We've only scratched the surface of what's possible with smart contracts on the BitTorrent Chain. For those eager to take their blockchain development skills to the next level, we've got a treasure trove of resources waiting for you in our GitHub repository!

🚀 Explore the Full Project

Head over to our BTTC Examples GitHub Repository to discover a wealth of additional content and features:

  1. Complete Contract Code: While we've covered the main functions, the repository contains the full smart contract code, including any methods we didn't have space to discuss here.
  2. Deployment Scripts: Ever wondered how to deploy your smart contracts to the BTTC network? We've got you covered with ready-to-use deployment scripts that make the process a breeze.
  3. Comprehensive Tests: Writing tests for smart contracts is crucial for ensuring their reliability and security. Our repository includes a suite of tests that demonstrate best practices in smart contract testing.
  4. Multiple Projects: Beyond the contract we've discussed today, you'll find a variety of other smart contract examples, from simple to advanced, showcasing different aspects of blockchain development on BTTC.
  5. Documentation: Detailed README files and inline comments provide additional context and explanations, making it easier to understand and modify the code for your own projects.

🛠️ Getting Started

To make the most of these resources:

  1. Clone the repository: git clone https://github.com/adeelch9/bttc-examples.git
  2. Navigate to the project directory of your choice
  3. Follow the setup instructions in the project's README
  4. Experiment with the contracts, run tests, and try deploying to a testnet

🌟 Why This Matters

By exploring the full repository, you'll gain:

- A deeper understanding of smart contract development

- Hands-on experience with deployment and testing

- Exposure to best practices in blockchain development

- Inspiration for your own BTTC projects

Whether you're a beginner looking to learn or an experienced developer seeking to refine your skills, our BTTC Examples repository is your gateway to mastering smart contract development on the BitTorrent Chain.

Happy coding, and may your blockchain journey be filled with innovation and success.

18 Sep 2024 6:42am GMT