[NEM] mosaicで商品購入ページを作りたい

基本的にはsendと同じだが、商品を選択して、商品数を入力できるようにすれば良い

		<div class="card column">
			<center><input type="radio" name="art" value="1" checked></center>
		</div>
		<div class="card column">
			<center><input type="radio" name="art" value="2"></center>
		</div>
		<div class="card column">
			<center><input type="radio" name="art" value="3"></center>
		</div>

		<div class="field" width="90%" style="margin:20px">
			<label class="label">Amount</label>
			<div class="control ">
				<input class="input" size="3" type="number" id="amount" style="width: 33%;" placeholder="" value="1">
			</div>
		</div>

js: 商品情報を連想配列で持って、radioボタンが押された時に、配列の何番目かを取得すれば良い

		var products = [
			{name:"Rime ethics", price:"20"},
			{name:"Midnight Asia", price:"30"},
			{name:"Dreams & Struggle", price:"90"},
		]

		// 省略

		function OnButtonClick() {
			let checkValue = "";
			let elements = document.getElementsByName('art');
			for (let i = 0; i < elements.length; i++){
			    if (elements.item(i).checked){
			        checkValue = i;
			    } 
			}
			sendAmountNem = parseInt(products[checkValue]['price']) * amount.value;
			name = products[checkValue]['name'];
			if (!walletpassword.value || !privatekey.value) {
			    resArea.innerHTML = "Wallet Password、privatekeyを入力してください";
			} else {
			    main();
			}		
			
		}

割とやりたいことはできたか…

[NEM] Wallet情報の取得

var nem = require("nem-sdk").default;

const endpoint = nem.model.objects.create('endpoint')(nem.model.nodes.defaultMainnet, nem.model.nodes.defaultPort);

const mainnetAddress = '****'

async function main() {
	await nem.com.requests.account.data(endpoint, mainnetAddress).then(res => {
		console.log('balance:', res.account);
	}).catch(err => {
		console.log(err);
	});
}

main();

$ node wallet.js
balance: { address: ‘****’,
harvestedBlocks: 0,
balance: 00000000,
importance: 0,
vestedBalance: 00000000,
publicKey:
‘****’,
label: null,
multisigInfo: {} }

なるほどね、アカウントにいくら入ってるかってのは誰でも見れちゃうんだな

[JavaScript] inputに入力があれbuttonを押せるようにする

btn.disabled = true; でbuttonを制御します。
input.addEventListener(“change”, func); で btn.disabledの状態を変更する

let btn = document.getElementById('btn');
		let wallet = document.getElementById('wallet');
		let message = document.getElementById('message');
		let amount = document.getElementById('amount');
		let resArea = document.getElementById("resArea");
		btn.disabled = true; 
		wallet.addEventListener("change", stateHandle);
		amount.addEventListener("change", stateHandle);
		message.addEventListener("change", stateHandle);
		function stateHandle() {
		  if (wallet.value == "" || amount.value == "") {
		    btn.disabled = true; 
		  } else {
		    btn.disabled = false;
		  }
		}

		function OnButtonClick() {
			if (!wallet.value || !message.value || !amount.value) {
			    resArea.innerHTML = "Wallet Address、amount、messageを入力してください";
			} else {
			    main();
			}		
			
		}
		async function main() {
			console.log("送金完了しました")
			console.log(wallet.value)
			console.log(message.value)
			console.log(amount.value)
			resArea.innerHTML = "送金完了しました";
		}

最初

入力後

OK
これで実際に送金できるかテストする

しゃあああああああああああああああああああ
次はxem amountの取得かな

[NEM] node.jsでmosaicを送信

nem-sdkをインストールします
$ npm install nem-sdk

mainnetで送信します。

var nem = require("nem-sdk").default;

const endpoint = nem.model.objects.create('endpoint')(nem.model.nodes.defaultMainnet, nem.model.nodes.defaultPort);

async function main() {

    const toAddress = '';
    const sendAmount = 1;
    const sendMsg = 'Hello World!';
    const password = '';
    const privateKey = '';
    const common = nem.model.objects.create('common')(password, privateKey);
    const yourMosaicNamespace = 'capitalcoin';
    const yourMosaicName = 'hpscript';

    let transferTransaction = nem.model.objects.create('transferTransaction')(toAddress, sendAmount, sendMsg);

    const xemMozaic = nem.model.objects.create('mosaicAttachment')('nem', 'xem', 0);
    transferTransaction.mosaics.push(xemMozaic);

    const yourMosaic = nem.model.objects.create('mosaicAttachment')(yourMosaicNamespace, yourMosaicName, 10);
    transferTransaction.mosaics.push(yourMosaic);

    let mosaicDefinitionMetaDataPair = nem.model.objects.get('mosaicDefinitionMetaDataPair');
    nem.com.requests.namespace.mosaicDefinitions(endpoint, yourMosaic.mosaicId.namespaceId).then(res => {

        const neededDefinition = nem.utils.helpers.searchMosaicDefinitionArray(res.data, [yourMosaicName]);

        const fullMosaicName  = nem.utils.format.mosaicIdToName(yourMosaic.mosaicId);

        if (undefined === neededDefinition[fullMosaicName]) {
            return console.log('Mosaic not found !');
        }

        mosaicDefinitionMetaDataPair[fullMosaicName] = {};
        mosaicDefinitionMetaDataPair[fullMosaicName].mosaicDefinition = neededDefinition[fullMosaicName];

        nem.com.requests.mosaic.supply(endpoint, fullMosaicName).then(supplyRes => {

            mosaicDefinitionMetaDataPair['nem:xem'].supply = 8999999999;
            mosaicDefinitionMetaDataPair[fullMosaicName].supply = supplyRes.supply;

            const transactionEntity = nem.model.transactions.prepare('mosaicTransferTransaction')(common, transferTransaction, mosaicDefinitionMetaDataPair, nem.model.network.data.mainnet.id);

            nem.model.transactions.send(common, transactionEntity, endpoint).then(sendRes => {
                console.log('sendRes:', sendRes);
            }).catch(sendErr => {
                console.log('sendError:', sendErr);
            });
        }).catch(supplyErr => {
            console.log('supplyErr:', supplyErr);
        });
    }).catch(err => {
        console.log('mosaicDefinitionsError:', err);
    });
}

main();

$ node test.js
sendRes: { innerTransactionHash: {},
code: 1,
type: 1,
message: ‘SUCCESS’,
transactionHash:
{ data:
‘f08066a73d37f523482d6dc61a60e53db4cbd5097262f1ee419cae7ae4ad9a7a’ } }

送信結果

おおお、これをUIをつけてやりたい

<body>
	<div class="container">
		<h1 class="title">NEM Project</h1>
		<p>送金ボタンを押してください</p>
		<input type="button" value="送金" onclick="OnButtonClick();">
	</div>
	<script src="nem-sdk.js"></script>
	<script>
		var nem = require("nem-sdk").default;
		
		function OnButtonClick() {
			main();
			console.log("送金完了しました")
		}
		const endpoint = nem.model.objects.create('endpoint')(nem.model.nodes.defaultMainnet, nem.model.nodes.defaultPort);
		async function main() {
		    // 省略
		}
	</script>

あ、出来た^^

受け取るwalletのアドレスとメッセージを入力フォームにして、そこに送信できるようにしたい。

[NEM] NEM Walletから独自通貨(mosaic)を送金

Nem用のwalletであるRaccoon Walletをスマホにインストールし、ウォレットのアドレスを取得します。

RaccoonWallet
https://apps.apple.com/jp/app/raccoonwallet/id1437034062

NEM WalletからRaccoon Walletのアドレスへ、mosaicを送信します

Raccoon Wallet側で受け取ったトランザクションを確認

おおおお、なんか凄い
これをプログラムでやりたい。出来ればUI付きで

[Ethereum] UIをコントラクトに接続

$ mkdir greeter-dapp
$ truffle unbox react
$ truffle develop

truffle(develop)> compile
truffle(develop)> migrate

$ cp ../greeter/contracts/Greeter.sol contracts/

2_deploy_greeter.js

var GreeterContract = artifacts.require("./Greeter.sol");

module.exports = function(deployer) {
  deployer.deploy(GreeterContract);
};

client/src/App.js

import React, { Component } from "react";
import GreeterContract from "./contracts/Greeter.json";
import getWeb3 from "./getWeb3";

import "./App.css";

class App extends Component {
  state = { greeting: '', web3: null, accounts: null, contract: null };

  componentDidMount = async () => {
    try {
      // Get network provider and web3 instance.
      const web3 = await getWeb3();

      // Use web3 to get the user's accounts.
      const accounts = await web3.eth.getAccounts();

      // Get the contract instance.
      const networkId = await web3.eth.net.getId();
      const deployedNetwork = GreeterContract.networks[networkId];
      const instance = new web3.eth.Contract(
        GreeterContract.abi,
        deployedNetwork && deployedNetwork.address,
      );

      // Set web3, accounts, and contract to the state, and then proceed with an
      // example of interacting with the contract's methods.
      this.setState({ web3, accounts, contract: instance }, this.runExample);
    } catch (error) {
      // Catch any errors for any of the above operations.
      alert(
        `Failed to load web3, accounts, or contract. Check console for details.`,
      );
      console.error(error);
    }
  };

  runExample = async () => {
    const { accounts, contract } = this.state;

    const response = await contract.methods.greet().call();
    this.setState({greeting: response})
  };

  render() {
    if (!this.state.web3) {
      return <div>Loading Web3, accounts, and contract...</div>;
    }
    return (
      <div className="App">
        <h1>Greeter</h1>

        {this.state.greeting}

        <form>
          <label>
            New Greeting:
            <input type="text" value={this.state.greeting} onChange={this.handleGreetingChange}>
          </label>
        </form>
        <button onClick={this.formSubmitHandler}> Submit </button>
      </div>
    );
  }
}

export default App;

うーむ、ようわからん

[Ethereum] Web3を使ったスマートコントラクト

Web3はイーサリアムも操作できるようにするJSライブラリ
HTTPまたはIPC接続を使ってイサーリアムに接続するためのJSON-RPCラッパー
フロントエンド <-> Web3 <-> ブロックチェーン

### Web3のメソッド
getAccounts()
getBlockNumber()
getBalance()
sendTransaction()

web3.setProvider(provider) とする
web3ではPromiseを頻繁に使用する

metamaskはwe3を使っているサイトと簡単にやり取りができるブラウザ拡張
send
call(view/pure関数)

[Ethereum] テストプロジェクト FundraiserFactory

fundraiser_factory_test.js

const FundraiserFactoryContract = artifacts.require("FundraiserFactory");
const FundraiserContract = artifacts.require("Fundraiser");

contract("FundraiserFactory: deployment", ()=> {
	it("has been deployed", async() => {
		const fundraiserFactory = FundraiserFactoryContract.deployed();
		assert(fundraiserFactory, "fundraiser factory was not deployed");
	})
});

contract("FundraiserFactory: createFundraiser", (accounts) => {
	let fundraiserFactory;
	const name = "Beneficiary Name";
	const url = "beneficiaryname.org";
	const imageURL = "https://placekitten.com/600/350"
	const description = "Beneficiary Description"
	const beneficiary = accounts[1];

	it("increments the fundraisersCount", async() => {
		fundraiserFactory = await FundraiserFactoryContract.deployed();
		const currentFundraisersCount = fundraiserFactory.fundraisersCount();
		await fundraiserFactory.createFundraiser(
			name,
			url,
			imageURL,
			description,
			beneficiary
		);
		const newFundraisersCount = await fundraiserFactory.fundraisersCount();

		// assert.equal(
		// 	newFundraisersCount - currentFundraisersCount,
		// 	1,
		// 	"should increment by 1"
		// );
	});

	it("emits the FundraiserCreated event", async() => {
		fundraiserFactory = await FundraiserFactoryContract.deployed();
		const tx = await fundraiserFactory.createFundraiser(
			name,
			url,
			imageURL,
			description,
			beneficiary
		);
		const expectedEvent = "FundraiserCreated";
		const actualEvent = tx.logs[0].event;

		assert.equal(actualEvent, expectedEvent, "event should match");
	})

});

contract("FundraiserFactory: fundraisers", (accounts) => {
	async function createFundraiserFactory(fundraiserCount, accounts){
		const factory = await FundraiserFactoryContract.new();
		await addFundraisers(factory, fundraiserCount, accounts);
		return factory;
	}

	async function addFundraisers(factory, count, accounts){
		const name = "Beneficiary";
		const lowerCaseName = name.toLowerCase();
		const beneficiary = accounts[1];

		for (let i = 0; i < count; i++){
			await factory.createFundraiser(
				`${name} ${i}`,
				`${lowerCaseName}${i}.com`,
				`${lowerCaseName}${i}.png`,
				`Description for ${name} ${i}`,
				beneficiary
			);
		}
	}

	describe("when fundraisers collection is empty", () => {
		it("returns an empty collection", async() => {
			const factory = await createFundraiserFactory(0, accounts);
			const fundraisers = await factory.fundraisers(10, 0);
			assert.equal(
				fundraisers.length,
				0,
				"collection should be empty"
			);
		});
	});

	describe("varying limits", async() => {
		let factory;
		beforeEach(async() => {
			factory = await createFundraiserFactory(30, accounts);
		});

		it("returns 10 results when limit requested is 10", async()=> {
			const fundraisers = await factory.fundraisers(10, 0);
			assert.equal(
				fundraisers.length,
				10,
				"results size should be 10"
			);
		});
		xit("returns 20 results when limit requested is 20", async() => {
			const fundraisers = await factory.fundraisers(20, 0);
			assert.equal(
				fundraisers.length,
				20,
				"results size should be 20"
			);
		});
		xit("returns 20 results when limit requested is 30", async() => {
			const fundraisers = await factory.fundraisers(30, 0);
			assert.equal(
				fundraisers.length,
				20,
				"results size should be 20"
			);
		});

	});

	describe("varying offset", () => {
		let factory;
		beforeEach(async() => {
			factory = await createFundraiserFactory(10, accounts);
		});

		it("contains the fundraiser with the appropriate offset", async() => {
			const fundraisers = await factory.fundraisers(1, 0);
			const fundraiser = await FundraiserContract.at(fundraisers[0]);
			const name = await fundraiser.name();
			assert.ok(await name.includes(0), `${name} did not include the offset`);
		});

		it("contains the fundraiser with the appropriate offset", async() => {
			const fundraisers = await factory.fundraisers(1, 7);
			const fundraiser = await FundraiserContract.at(fundraisers[0]);
			const name = await fundraiser.name();
			assert.ok(await name.includes(7), `${name} did not include the offset`);
		})
	});

	describe("boundary conditions", ()=> {
		let factory;
		beforeEach(async() => {
			factory = await createFundraiserFactory(10, accounts);
		});

		it("raises out of bounds error", async () => {
			try {
				await factory.fundraisers(1, 11);
				assert.fail("error was not raised")
			} catch(err) {
				const expected = "offset out of bounds";
				assert.ok(err.message.includes(expected), `${err.message}`);
			}
		});

		it("adjusts return size to prevent out of bounds error", async() => {
			try {
				const fundraisers = await factory.fundraisers(10, 5);
				assert.equal(
					fundraisers.length,
					5,
					"collection adjusted"
				);
			} catch(err) {
				assert.fail("limit and offset exceeded bounds");
			}
		})
	})
})

contracts

pragma solidity >0.4.23 <=0.8.0;

import "./Fundraiser.sol";

contract FundraiserFactory {
	uint256 constant maxLimit = 20;
	Fundraiser[] private _fundraisers;

	event FundraiserCreated(Fundraiser indexed fundraiser, address indexed owner);

	function createFundraiser(
		string memory name,
		string memory url,
		string memory imageURL,
		string memory description,
		address payable beneficiary
	)

	public {
		Fundraiser fundraiser = new Fundraiser(
			name,
			url,
			imageURL,
			description,
			beneficiary,
			msg.sender
		);
		_fundraisers.push(fundraiser);
		emit FundraiserCreated(fundraiser, fundraiser.owner());
	}

	function fundraisersCount() public view returns(uint256) {
		return _fundraisers.length;
	}

	function fundraisers(uint256 limit, uint256 offset) public view returns(Fundraiser[] memory coll){

		require(offset <= fundraisersCount(), "offset out of bounds");

		uint256 size = fundraisersCount() - offset;
		size = size < limit ? size : limit;
		size = size < maxLimit ? size : maxLimit;
		coll = new Fundraiser[](size);

		for(uint256 i = 0; i < size; i++){
			coll[i] = _fundraisers[offset + i];
		}

		return coll;
	}
}

関数とその機能を覚えていけば、行けそうな気がして来た

[Ethereum] テストプロジェクト fundraiser

$ mkdir fundraiser
$ cd fundraiser
$ truffle unbox react
$ tree
$ rm contracts/SimpleStorage.sol \
migrations/2_deploy_contracts.js \
test/*
$ touch contracts/Fundraiser.sol test/fundraiser_test.js

受取人の名前、Webサイト、受取人のアドレス、トップページのカードに使う画像URL、受取人に関する説明、管理人またはownerのアドレス

fundraiser_test.js

const FundraiserContract = artifacts.require("Fundraiser");

contract("Fundraiser", accounts => {
	let fundraiser;
	const name = "Beneficiary Name";
	const url = "beneficiaryname.org";
	const imageURL = "https://placekitten.com/600/350";
	const description = "Beneficiary description";
	const beneficiary = accounts[1];
	const owner = accounts[0];

	beforeEach(async() => {
		fundraiser = await FundraiserContract.new(
			name,
			url,
			imageURL,
			description,
			beneficiary,
			owner
		);
	});

	describe("initialization", () => {
		

		it("gets the beneficiary name", async() => {
			const actual = await fundraiser.name();
			assert.equal(actual, name, "names should match");
		});

		it("gets the beneficiary url", async() => {
			const actual = await fundraiser.url();
			assert.equal(actual, url, "url should match");
		});

		it("gets the beneficiary image url", async() => {
			const actual = await fundraiser.imageURL();
			assert.equal(actual, imageURL, "imageURL should match");
		});

		it("gets the beneficiary description", async() => {
			const actual = await fundraiser.description();
			assert.equal(actual, description, "description should match");
		});

		it("gets the beneficiary", async() => {
			const actual = await fundraiser.beneficiary();
			assert.equal(actual, beneficiary, "beneficiary addresses should match");
		});

		it("gets the owner", async() => {
			const actual = await fundraiser.owner();
			assert.equal(actual, owner, "bios should match");
		})

	});

	describe("setBeneficiary", () => {
		const newBeneficiary = accounts[2];

		it("updated beneficiary when called by owner account", async() => {
			await fundraiser.setBeneficiary(newBeneficiary, {from: owner});
			const actualBeneficiary = await fundraiser.beneficiary();
			assert.equal(actualBeneficiary, newBeneficiary,
				"beneficiaries should match");
		})

		it("throws an error when called from a non-owner account", async() => {
			try {
				await fundraiser.setBeneficiary(newBeneficiary, {from: accounts[3]});
				assert.fail("withdraw was not restricted to owners")
			} catch(err) {
				const expectedError = "Ownable: caller is not the owner"
				const actualError = err.reason;
				assert.equal(actualError, expectedError, "should not be permitted")
			}
		})
	});

	describe("making donations", () => {
		const value = web3.utils.toWei('0.0289');
		const donor = accounts[2];

		it("increases myDonationsCount", async() => {
			const currentDonationsCount = await fundraiser.myDonationsCount(
				{from: donor}
			);

			await fundraiser.donate({from: donor, value});

			const newDonationsCount = await fundraiser.myDonationsCount(
				{from: donor}
			);

			assert.equal(
				1,
				newDonationsCount - currentDonationsCount,
				"myDonationsCount should increment by 1"
			);
		});
		it("includes donation in myDonations", async() => {
			await fundraiser.donate({from: donor, value});
			const {values, dates} = await fundraiser.myDonations(
					{from: donor}
				);
			assert.equal(
					value,
					values[0],
					"values should match"
				);
			assert(dates[0], "date should be present");
		});
		it("increases the totalDonations amaount", async() => {
			const currentTotalDonations = await fundraiser.totalDonations();
			await fundraiser.donate({from: donor, value});
			const newTotalDonations = await fundraiser.totalDonations();

			const diff = newTotalDonations - currentTotalDonations;

			assert.equal(
				diff,
				value,
				"difference should match the donation value"
			);
		});
		it("increases donationsCount", async() => {
			const currentDonationsCount = await fundraiser.donationsCount();
			await fundraiser.donate({from: donor, value});
			const newDonationsCount = await fundraiser.donationsCount();

			assert.equal(
				1,
				newDonationsCount - currentDonationsCount,
				"donationsCount should increment by 1"
			)
		})
		it("emits the DonationReceived event", async() => {
			const tx = await fundraiser.donate({from: donor, value});
			const expectedEvent = "DonationReceived";
			const actualEvent = tx.logs[0].event;

			assert.equal(actualEvent, expectedEvent, "events should match");
		})
	});
	describe("withdrawing funds", ()=> {
		beforeEach(async() => {
			await fundraiser.donate(
				{from: accounts[2], value: web3.utils.toWei('0.1')}
			);
		});

		describe("access controls", () => {
			it("throws an error when called from a non-owner account", async() => {
				try {
					await fundraiser.withdraw({from: accounts[3]});
					assert.fail("withdraw was not restricted to owners");
				} catch(err) {
					const expectedError = "Ownable: caller is not the owner";
					const actualError = err.reason;
					assert.equal(actualError, expectedError, "should not be permitted");
				}
			});

			it("permits the owner to call the function", async() => {
				try {
					await fundraiser.withdraw({from: owner});
					assert(true, "no errors were thrown");
				} catch(err) {
					assert.fail("should not have thrown an error");
				}
			})
		});

		it("transfers balance to beneficiary", async() => {
			const currentContractBalance = await web3.eth.getBalance(fundraiser.address);
			const currentBeneficiaryBalance = await web3.eth.getBalance(beneficiary);

			await fundraiser.withdraw({from: owner});

			const newContractBalance = await web3.eth.getBalance(fundraiser.address);
			const newBeneficiaryBalance = await web3.eth.getBalance(beneficiary);
			const beneficiaryDifference = newBeneficiaryBalance - currentBeneficiaryBalance;

			assert.equal(
				newContractBalance,
				0,
				"contract should have a 0 balance"
			);
			assert.equal(
				beneficiaryDifference,
				currentContractBalance,
				"beneficiary should receive all the funds"
			);
		});

		it("emit Withdraw event", async()=>{
			const tx = await fundraiser.withdraw({from: owner});
			const expectedEvent = "Withdraw";
			const actualEvent = tx.logs[0].event;

			assert.equal(
				actualEvent,
				expectedEvent,
				"events should match"
			);
		});
	});
	describe("fallback function", () => {
		const value = web3.utils.toWei('0.0289');

		it("increases the totalDonation amount", async() => {
			const currentTotalDonations = await fundraiser.totalDonations();
			await web3.eth.sendTransaction(
				{to: fundraiser.address, from: accounts[9], value}
			);
			const newTotalDonations = await fundraiser.totalDonations();

			const diff = newTotalDonations - currentTotalDonations;

			assert.equal(
				diff,
				value,
				"difference should match the donation value"
			);
		});

		it("increase donationsCount", async() => {
			const currentDonationsCount = await fundraiser.donationsCount();
			await web3.eth.sendTransaction(
				{to: fundraiser.address, from: accounts[9], value}
			);
			const newDonationsCount = await fundraiser.donationsCount();

			assert.equal(
				1,
				newDonationsCount - currentDonationsCount,
				"donationsCount should increment by 1"
			);
		});
	});
});

Fundraiser.sol

pragma solidity >0.4.23 <=0.8.0;

import "openzeppelin-solidity/contracts/access/Ownable.sol";
import "openzeppelin-solidity/contracts/utils/math/SafeMath.sol";

contract Fundraiser is Ownable{
	using SafeMath for uint256;

	uint256 public totalDonations;
	uint256 public donationsCount;
	event DonationReceived(address indexed donor, uint256 value);
	event Withdraw(uint256 amount);

	struct Donation {
		uint256 value;
		uint256 date;
	}
	mapping(address => Donation[]) private _donations;

	string public name;
	string public url;
	string public imageURL;
	string public description;

	address payable public beneficiary;

	constructor(
		string memory _name,
		string memory _url,
		string memory _imageURL,
		string memory _description,
		address payable _beneficiary,
		address _custodian
	)

	public {
		name = _name;
		url = _url;
		imageURL = _imageURL;
		description = _description;
		beneficiary = _beneficiary;
		transferOwnership(_custodian);
	}

	function setBeneficiary(address payable _beneficiary) public onlyOwner {
		beneficiary = _beneficiary;
	}

	function myDonationsCount() public view returns(uint256){
		return _donations[msg.sender].length;
	}

	function donate() public payable {
		Donation memory donation = Donation({
			value: msg.value,
			date: block.timestamp
		});
		_donations[msg.sender].push(donation);
		totalDonations = totalDonations.add(msg.value);
		donationsCount++;

		emit DonationReceived(msg.sender, msg.value);
	}

	function myDonations() public view returns(
		uint256[] memory values,
		uint256[] memory dates
	){
		uint256 count = myDonationsCount();
		values = new uint256[](count);
		dates = new uint256[](count);

		for (uint256 i = 0; i < count; i++){
			Donation storage donation = _donations[msg.sender][i];
			values[i] = donation.value;
			dates[i] = donation.date;
		}

		return (values, dates);
	}

	function withdraw() public onlyOwner {
		uint256 balance = address(this).balance;
		beneficiary.transfer(balance);
		emit Withdraw(balance);
	}

	fallback () external payable {
		totalDonations = totalDonations.add(msg.value);
		donationsCount++;
	}
}

address型とaddress payable型の二つのアドレスがある
少しずつ理解してきました

[NEM/XEM] 独自トークンの発行

NEMのサイトに飛びます
https://discord.com/invite/xymcity

これはdiscordのチャットですね

Symbol
https://jp.symbolplatform.com/

Nemplatform wallet

Wallets


これか

import してログインする

namespace : 独自トークンを機能させるための場所
mosaic : トークの詳細設定(名称、初期供給量、小数点)

早速NEM Walletにnemを送ってみます。120NEMが必要ということなので、124NEM送る
NEMはBlock chainに比べて、blockが作られる時間が早い
https://explorer.nemtool.com/

すると、アカウントに124NEMが入っている!

### namespace
create namespaceでcapitalcoinとします
すると、100.15NEM引かれて、Dashboardでnamespaceが作られます

### Mosaics
namespaceが作られると、mosaicsの作成ができるようになります。
Mosaic name: hpscript
Description: Hpscript
Initial Supply: 100000000
Total Supply: 100000000

### Mosaicの送信
もにゃに送信できるらしいが、もにゃ側でエラーになる…

発行は簡単にできるが、使い方がイマイチやな