SlideShare a Scribd company logo
1 of 69
Download to read offline
//	Estructura
struct	Organization	{
				uint	id;
				address	owner;
				string	name;
}
//	Array
Organization[]	public	organizations;
//	Mapping
mapping(address	=>	uint)	public	ownerToOrganizationId;
//	Constructor
constructor()	public	{
				//	to	fix	problem	with	nulls
				organizations.push(Organization(0,	0,	"0"));
}
//	Eventos
event	OrganizationCreated(
				uint	indexed	id,	address	indexed	owner,	string	name);
//	Modificadores	personalizados
modifier	ownerNotExists()	{
				require(ownerToOrganizationId[msg.sender]	==	0,	
				"suplied	owner	already	have	an	organization");
				_;
}
function	addOrganization(string	_name)	external	
				ownerNotExists()	{
				...
				emit	OrganizationCreated(organizationId,	msg.sender,	_name);
}
function	donation(uint	_organizationId)	external	payable
				ownerExists(_organizationId)	{
				...
				emit	DonationSubmitted(_organizationId,	owner,	msg.sender,	msg.value);
}
function	getOrganizationsLength()	external	view	returns(uint)	{
				return	organizations.length;
}
#	instalar
npm	install	-g	ganache-cli
#	ejecutar
ganache-cli	--gasLimit	7000001	--mnemonic	"$(cat	wallet.mnemonic)"
#	instalar
npm	install	-g	truffle
#	compilar
truffle	compile
#	migrar
truffle	migrate
var	NonGovernmentalOrganizations	=	artifacts
				.require("NonGovernmentalOrganizations");
contract("NonGovernmentalOrganizations",	async	(accounts)	=>	{
				it("addOrganization	-	ok",	async	()	=>	{
								let	instance	=	await	NonGovernmentalOrganizations.deployed();
								let	tx	=	await	instance.addOrganization(expectedName,
												{	from:	expectedOwner	});
								assert.equal(tx.logs[0].event,	"OrganizationCreated");
								let	result	=	await	instance.organizations.call(expectedId);
								assert.equal(result[2],	expectedName);
								let	ownerId	=	await	instance.ownerToOrganizationId(expectedOwner);
								assert.equal(ownerId,	expectedId);
								let	length	=	await	instance.getOrganizationsLength();
								assert.equal(length,	expectedLength);
				});
});
#	testear
truffle	test
#	instalar
npm	install	-g	@angular/cli
#	ejecutar
ng	serve
getUserAddress()	{
				if	(!this.web3)	{
								this.messagesService.sendErrorMessage('Try	MetaMask.');
				}
				this.web3.eth.getAccounts().then(accounts	=>	{
								if	(!accounts	||	accounts.length	===	0)	{
												this.messagesService.sendErrorMessage('No	user	accounts.');
								}
								if	(StorageUtil.getUserAddress()	!==	accounts[0])	{
												StorageUtil.setUserAddress(accounts[0]);
												this.messagesService.sendNewUserAddressMessage(accounts[0]);
								}
				}).catch(error	=>	{
								this.messagesService.sendErrorMessage(error);
				});
}
async	getContractInstance():	Promise<any>	{
				if	(!this.web3)	{
								throw	new	Error('web3	server	not	found.	Try	MetaMask.');
				}
				const	ngoContract	=	contract(artifacts);
				ngoContract.setProvider(this.web3.currentProvider);
				try	{
								const	ngoInstance	=	await	ngoContract.deployed();
								return	ngoInstance;
				}	catch	(error)	{
								console.log(error);
								throw	new	Error('Contract	has	not	been	deployed	to	network.');
				}
}
async	add(organization:	Organization):	Promise<Organization>	{
				const	contractInstance	=	await	this.web3Service.getContractInstance();
				const	oldOrganization	=	await	this.getCurrentUserOrganizationAsOwner();
				if	(oldOrganization)	{
								throw	new	Error('The	user	is	already	owner	of	an	organization.');
				}
				const	transaction	=	await	contractInstance.addOrganization(
								organization.name,	{	from:	this.senderAddress	});
				const	newOrganization	=	this._getOrganizationFromTransaction(transaction);
				this.organizations.push(newOrganization);
				console.log('OrganizationService->add',	newOrganization);
				return	newOrganization;
}
async	donation(id:	number,	ethValue:	number):	Promise<Donation>	{
				const	organization	=	await	this.getOne(id);
				const	contractInstance	=	await	this.web3Service.getContractInstance();
				const	weiValue	=	this.web3Service.etherToWei(ethValue.toString());
				const	transaction	=	await	contractInstance.donation(organization.id,	
								{	value:	weiValue,	from:	this.senderAddress	});
				const	donation	=	await	this._getDonationFromTransaction(transaction);
				console.log('OrganizationService->donation',	donation);
				return	donation;
}
#	empaquetar
ng	build	--prod
var	HDWalletProvider	=	require("truffle-hdwallet-provider");
module.exports	=	{
		networks:	{
				rinkeby:	{
						provider:	function	()	{
								let	provider	=	new	HDWalletProvider(
										walletMmnemonic,
										"https://rinkeby.infura.io/v3/"	+	apiKey);
								return	provider;
						},
						gas:	7000001,
						network_id:	4
				}
		}
};
truffle	migrate	--network	rinkeby
Managing non-profits on blockchain
Managing non-profits on blockchain
Managing non-profits on blockchain
Managing non-profits on blockchain
Managing non-profits on blockchain
Managing non-profits on blockchain
Managing non-profits on blockchain
Managing non-profits on blockchain
Managing non-profits on blockchain
Managing non-profits on blockchain
Managing non-profits on blockchain
Managing non-profits on blockchain
Managing non-profits on blockchain

More Related Content

What's hot

Business News, Personal Finance and Money News
Business News, Personal Finance and Money NewsBusiness News, Personal Finance and Money News
Business News, Personal Finance and Money Newsacousticassista07
 
Kick start with j query
Kick start with j queryKick start with j query
Kick start with j queryMd. Ziaul Haq
 
Modern Android Architecture
Modern Android ArchitectureModern Android Architecture
Modern Android ArchitectureEric Maxwell
 
Effective Android Data Binding
Effective Android Data BindingEffective Android Data Binding
Effective Android Data BindingEric Maxwell
 
iOS. EventKit Framework. Work with calendars and reminders
iOS. EventKit Framework. Work with calendars and remindersiOS. EventKit Framework. Work with calendars and reminders
iOS. EventKit Framework. Work with calendars and remindersVoityuk Alexander
 
Business News, Personal Finance and Money News
Business News, Personal Finance and Money NewsBusiness News, Personal Finance and Money News
Business News, Personal Finance and Money Newsblogginatl1963
 

What's hot (6)

Business News, Personal Finance and Money News
Business News, Personal Finance and Money NewsBusiness News, Personal Finance and Money News
Business News, Personal Finance and Money News
 
Kick start with j query
Kick start with j queryKick start with j query
Kick start with j query
 
Modern Android Architecture
Modern Android ArchitectureModern Android Architecture
Modern Android Architecture
 
Effective Android Data Binding
Effective Android Data BindingEffective Android Data Binding
Effective Android Data Binding
 
iOS. EventKit Framework. Work with calendars and reminders
iOS. EventKit Framework. Work with calendars and remindersiOS. EventKit Framework. Work with calendars and reminders
iOS. EventKit Framework. Work with calendars and reminders
 
Business News, Personal Finance and Money News
Business News, Personal Finance and Money NewsBusiness News, Personal Finance and Money News
Business News, Personal Finance and Money News
 

Similar to Managing non-profits on blockchain

Understand Properties in Codename One
Understand Properties in Codename One Understand Properties in Codename One
Understand Properties in Codename One Shai Almog
 
Persisting Data on SQLite using Room
Persisting Data on SQLite using RoomPersisting Data on SQLite using Room
Persisting Data on SQLite using RoomNelson Glauber Leal
 
properties-how-do-i.pdf
properties-how-do-i.pdfproperties-how-do-i.pdf
properties-how-do-i.pdfShaiAlmog1
 
Knockoutjs UG meeting presentation
Knockoutjs UG meeting presentationKnockoutjs UG meeting presentation
Knockoutjs UG meeting presentationValdis Iljuconoks
 
Creating an Uber Clone - Part XXXX.pdf
Creating an Uber Clone - Part XXXX.pdfCreating an Uber Clone - Part XXXX.pdf
Creating an Uber Clone - Part XXXX.pdfShaiAlmog1
 
Introduction to CQRS and Event Sourcing
Introduction to CQRS and Event SourcingIntroduction to CQRS and Event Sourcing
Introduction to CQRS and Event SourcingSamuel ROZE
 

Similar to Managing non-profits on blockchain (8)

Build your own entity with Drupal
Build your own entity with DrupalBuild your own entity with Drupal
Build your own entity with Drupal
 
Understand Properties in Codename One
Understand Properties in Codename One Understand Properties in Codename One
Understand Properties in Codename One
 
Mattbrenner
MattbrennerMattbrenner
Mattbrenner
 
Persisting Data on SQLite using Room
Persisting Data on SQLite using RoomPersisting Data on SQLite using Room
Persisting Data on SQLite using Room
 
properties-how-do-i.pdf
properties-how-do-i.pdfproperties-how-do-i.pdf
properties-how-do-i.pdf
 
Knockoutjs UG meeting presentation
Knockoutjs UG meeting presentationKnockoutjs UG meeting presentation
Knockoutjs UG meeting presentation
 
Creating an Uber Clone - Part XXXX.pdf
Creating an Uber Clone - Part XXXX.pdfCreating an Uber Clone - Part XXXX.pdf
Creating an Uber Clone - Part XXXX.pdf
 
Introduction to CQRS and Event Sourcing
Introduction to CQRS and Event SourcingIntroduction to CQRS and Event Sourcing
Introduction to CQRS and Event Sourcing
 

More from Adolfo Sanz De Diego

De 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWKDe 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWKAdolfo Sanz De Diego
 
Codemotion 2017 - Taller de JHipster
Codemotion 2017 - Taller de JHipsterCodemotion 2017 - Taller de JHipster
Codemotion 2017 - Taller de JHipsterAdolfo Sanz De Diego
 
Codemotion 2017 - La Revolución del Software Libre
Codemotion 2017 - La Revolución del Software LibreCodemotion 2017 - La Revolución del Software Libre
Codemotion 2017 - La Revolución del Software LibreAdolfo Sanz De Diego
 
Open Expo 2017 - La Revolución del Software Libre
Open Expo 2017 - La Revolución del Software LibreOpen Expo 2017 - La Revolución del Software Libre
Open Expo 2017 - La Revolución del Software LibreAdolfo Sanz De Diego
 
JustiApps #hackTheJustice - Y si quiero desarrollar mi propia app, ¿qué debo ...
JustiApps #hackTheJustice - Y si quiero desarrollar mi propia app, ¿qué debo ...JustiApps #hackTheJustice - Y si quiero desarrollar mi propia app, ¿qué debo ...
JustiApps #hackTheJustice - Y si quiero desarrollar mi propia app, ¿qué debo ...Adolfo Sanz De Diego
 
¿Qué es un hackathon y por qué deberías asistir?
¿Qué es un hackathon y por qué deberías asistir?¿Qué es un hackathon y por qué deberías asistir?
¿Qué es un hackathon y por qué deberías asistir?Adolfo Sanz De Diego
 
Nuestro primer HackLab -We want you for HackthonLovers #wantu4hl
Nuestro primer HackLab -We want you for HackthonLovers #wantu4hlNuestro primer HackLab -We want you for HackthonLovers #wantu4hl
Nuestro primer HackLab -We want you for HackthonLovers #wantu4hlAdolfo Sanz De Diego
 

More from Adolfo Sanz De Diego (20)

Redes
RedesRedes
Redes
 
Computación
ComputaciónComputación
Computación
 
Angular
AngularAngular
Angular
 
TypeScript
TypeScriptTypeScript
TypeScript
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Java 8
Java 8Java 8
Java 8
 
De 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWKDe 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWK
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Codemotion 2017 - Taller de JHipster
Codemotion 2017 - Taller de JHipsterCodemotion 2017 - Taller de JHipster
Codemotion 2017 - Taller de JHipster
 
Codemotion 2017 - La Revolución del Software Libre
Codemotion 2017 - La Revolución del Software LibreCodemotion 2017 - La Revolución del Software Libre
Codemotion 2017 - La Revolución del Software Libre
 
Git, Github y Markdown
Git, Github y MarkdownGit, Github y Markdown
Git, Github y Markdown
 
Open Expo 2017 - La Revolución del Software Libre
Open Expo 2017 - La Revolución del Software LibreOpen Expo 2017 - La Revolución del Software Libre
Open Expo 2017 - La Revolución del Software Libre
 
JustiApps #hackTheJustice - Y si quiero desarrollar mi propia app, ¿qué debo ...
JustiApps #hackTheJustice - Y si quiero desarrollar mi propia app, ¿qué debo ...JustiApps #hackTheJustice - Y si quiero desarrollar mi propia app, ¿qué debo ...
JustiApps #hackTheJustice - Y si quiero desarrollar mi propia app, ¿qué debo ...
 
¿Qué es un hackathon y por qué deberías asistir?
¿Qué es un hackathon y por qué deberías asistir?¿Qué es un hackathon y por qué deberías asistir?
¿Qué es un hackathon y por qué deberías asistir?
 
Codemotion 2016 - Hackathones 101
Codemotion 2016 - Hackathones 101Codemotion 2016 - Hackathones 101
Codemotion 2016 - Hackathones 101
 
Hackeando el #psd2Hackathon
Hackeando el #psd2HackathonHackeando el #psd2Hackathon
Hackeando el #psd2Hackathon
 
Open Expo 2016 - Ética Hacker
Open Expo 2016 - Ética HackerOpen Expo 2016 - Ética Hacker
Open Expo 2016 - Ética Hacker
 
Nuestro primer HackLab -We want you for HackthonLovers #wantu4hl
Nuestro primer HackLab -We want you for HackthonLovers #wantu4hlNuestro primer HackLab -We want you for HackthonLovers #wantu4hl
Nuestro primer HackLab -We want you for HackthonLovers #wantu4hl
 
T3chFest - 2016 - Ética Hacker
T3chFest - 2016 - Ética HackerT3chFest - 2016 - Ética Hacker
T3chFest - 2016 - Ética Hacker
 
Git, GitHub y Markdown
Git, GitHub y MarkdownGit, GitHub y Markdown
Git, GitHub y Markdown
 

Recently uploaded

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 

Recently uploaded (20)

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 

Managing non-profits on blockchain