ð¶Aptosã®ãã¥ãŒããªã¢ã«ãèªãã§ç°¡æDAppãäœã£ãŠã¿ãð¶
çãããããã«ã¡ã¯ïŒ
ä»åã¯ãå æ¥ã¡ã€ã³ããããããŒã³ãããã°ããã®ãããã¯ãã§ãŒã³ã§ããAptosã®ãã¥ãŒããªã¢ã«ãèªãã§ç°¡æDappãäœã£ãŠã¿ãã®ã§ãã®èšé²ããŸãšããŠãããŸãïŒ
Aptosã®ã¹ããŒãã³ã³ãã©ã¯ãã¯ãRustèšèªã©ã€ã¯ãªããã°ã©ãã³ã°èšèªã§ããMoveèšèªã§éçºããŸãïŒ
èå³ãããæ¹ã¯ãã²èªã¿é²ãã§ã¿ãŠãã ããïŒ
ãœãŒã¹ã¯äžèšã®ãªããžããªã«ãŸãšããŠããŸãïŒ
ç®æ¬¡
- Aptosã«ã€ããŠ
- ä»åãã£ããã¥ãŒããªã¢ã«ã®æŠèŠ
- äœã£ãDAppã®æŠèŠ
- ãœãŒã¹ã³ãŒããªã©
- ãã®ä»Aptosäžã«å±éãããŠããæ°ã«ãªã£ããããã¯ã
- æåŸã«
1. Aptosã«ã€ããŠ
ãŸãã¯ãç°¡åã«Aptosã«ã€ããŠãŸãšããŠãããŸãïŒ
Aptosã¯ãéçºäžã®L1(Layer 1)ãããã¯ãã§ãŒã³ããã®ãããžã§ã¯ãã®ç·ç§°ã§ãé«åŠçèœåã»äœé 延ã匷ã¿ãšããŠããŸãã
ã¹ããŒãã³ã³ãã©ã¯ããæ±ãããšãã§ãããããAvalancheãSolanaãšãã£ããã§ãŒã³ãšç«¶åãããããžã§ã¯ãã§ããAptosã¯ãDiemã®å ã¡ã³ããŒã§ããMo Shaikhæ°ã»Avery Chingæ°ãäžå¿ãšãªã£ãŠéçºãã¹ã¿ãŒãããŠããŠãã©ã€ãã«ãããžã§ã¯ããšããŠã¯ãSuiãæããããŸãã
googleãšãããŒãããŒã·ãããææºããŠãããWeb3éçºç°å¢ã®æŽåãããã«ãœã³ã®éå¬ãäŒç»ãããŠãããšããããšã§ãããŸã§ã®ãããã¯ãã§ãŒã³ãããžã§ã¯ããšã¯ãŸãéã£ãã¢ãããŒãã§äžã®äžãžã®æ®åãå³ãããšããŠããŸãã
å æ¥ã¡ã€ã³ããããããŒã³ããããŸãããããã¹ããããå ¬éã®æç¹ã§ããã§ã«100以äžã®ãããžã§ã¯ããAptosäžã«å±éãããŠãããšããããšã§ããªã泚ç®åºŠãé«ãã£ããããã¯ãã§ãŒã³ã«ãªããŸãã
äžèšãµã€ããããããžã§ã¯ãã®äžèŠ§ã確èªã§ããŸãã
éçºã«äœ¿çšãããŠããã®ã¯ããã®Diemã§ãæ¡çšãããŠãããšããMoveèšèªã«ãªããŸãã
Moveèšèªã¯RustèšèªãããŒã¹ã«äœãããŠããã®ã§èŠãç®ãRustã«äŒŒãŠããŸãïŒãã®ãããè€æ°ã¿ã¹ã¯ã䞊ååŠçã§ããããšãå®å šãªã¡ã¢ãªç®¡çã®ä»çµã¿ãªã©Rustèšèªã®è¯ãéšåãç¶æ¿ãããŠããŸãã
ã³ã³ã»ã³ãµã¹ã¢ã«ãŽãªãºã ã«ã¯ãBullshark /ãã«ãŒã·ã£ãŒã¯ãšåŒã°ãããã®ãæ¡çšãããŠããŸããBullsharkã¯ãHotStuffãšããã³ã³ã»ã³ãµã¹ã¢ã«ãŽãªãºã ãããŒã¹ã«äœãããŠãããé«éæ§ãå®å šæ§ãããã«æ¹åãããã®ãšãªã£ãŠããŸãã
ã³ã³ã»ã³ãµã¹ã¢ã«ãŽãªãºã ã«ã€ããŠã¯ãŸãã«ä»ãäžçäžã§ããè¯ãã¢ã«ãŽãªãºã ãç 究ãããŠããçã£æäžãªã®ã§ä»åŸã¯ããã«è¯ãã¢ã«ãŽãªãºã ãçã¿åºãããŠããå¯èœæ§ããããŸãïŒïŒ
ããšãç¹çãã¹ãç¹ãšããŠã¯ã»ãã¥ãªãã£é¢ã§ãé¢çœãè©Šã¿ãããŠããŸããåŸæ¥ã®ä»çµã¿ã§ããã°äžåºŠçŽå€±ããæ¥ç§å¯éµã¯ãäœããã®ããã¯ã¢ããããªãå Žåã«ã¯åŸ©å ããããšãäžå¯èœã§ããããAptosã§ã¯ãããå¯èœã«ããããã®ä»çµã¿ãäœãããšãããããŠãããšã®ããšã§ãã
ç§å¯éµã®çé£é²æ¢ã®ããã«ããŒããŒã·ã§ã³æ©èœãªã©ãåããããŠããåŸæ¥ã®ãããã¯ãã§ãŒã³ãããžã§ã¯ããæ±ããŠãã課é¡ã解決ããããšããŠããŸãã
Aptosã«ã€ããŠã®ç°¡åãªæŠèŠã¯ãããŸã§ãšããããšæããŸãïŒïŒ
2. ä»åãã£ããã¥ãŒããªã¢ã«ã®æŠèŠ
ä»åãã©ã€ãããã¥ãŒããªã¢ã«ã§ãããäžèšãµã€ããåèã«é çªã«å®æœããŠãããŸããïŒ
CLIã®ã€ã³ã¹ããŒã«ã«å§ãŸãããã©ã³ã¶ã¯ã·ã§ã³ã®éä¿¡ãç°¡åãªã¹ããŒãã³ã³ãã©ã¯ãã®å®è£ ãdappã®å®è£ ãšãã£ãå ·åã§ãïŒïŒ
ãŸãã¯ãCLIã®ã€ã³ã¹ããŒã«ããã§ãïŒ
åºæ¬çã«ã¯éçºè åãããã¥ã¡ã³ãã®æ瀺ã«åŸã£ãŠé²ããŠããã°åé¡ãªãã€ã³ã¹ããŒã«ã§ãããšæããŸãïŒ
ã€ã³ã¹ããŒã«ãããŸãããã°ã aptos -h
ãšå
¥åãããšæ¬¡ã®ãããªå
容ãã¿ãŒããã«ã«åºåããããšæããŸã!
Command Line Interface (CLI) for developing and interacting with the Aptos blockchain
USAGE:
aptos <SUBCOMMAND>
OPTIONS:
-h, --help Print help information
-V, --version Print version information
SUBCOMMANDS:
account Tool for interacting with accounts
config Tool for interacting with configuration of the Aptos CLI tool
genesis Tool for setting up an Aptos chain Genesis transaction
governance Tool for on-chain governance
help Print this message or the help of the given subcommand(s)
info Show build information about the CLI
init Tool to initialize current directory for the aptos tool
key Tool for generating, inspecting, and interacting with keys
move Tool for Move related operations
node Tool for operations related to nodes
stake Tool for manipulating stake
Aptos SDKã®ã€ã³ã¹ããŒã«ã¯ã次ã®ã³ãã³ãã§å®è¡ã§ããŸãïŒ
npm i aptos
ããŠããŸãã¯ãã¥ãŒããªã¢ã«ã®æåãããããŸãã
Your Fisrt Transaction
https://github.com/aptos-labs/aptos-core.gitããgitãcloneããŠããŸãã
æåã®ãã¥ãŒããªã¢ã«ã§å®è¡ããã®ã¯ãtransfer_coin.ts
ãšããã¹ã¯ãªããã«ãªããŸãã
äžèº«ãç°¡åã«æ²èŒããŸãã
import dotenv from "dotenv";
dotenv.config();
import {
AptosClient,
AptosAccount,
CoinClient,
FaucetClient
} from "aptos";
import {
NODE_URL,
FAUCET_URL
} from "./common";
(async () => {
// Create API and faucet clients.
const client = new AptosClient(NODE_URL);
const faucetClient = new FaucetClient(NODE_URL, FAUCET_URL);
// Create client for working with the coin module.
const coinClient = new CoinClient(client);
// Create accounts.
const alice = new AptosAccount();
const bob = new AptosAccount();
// Print out account addresses.
console.log("=== Addresses ===");
console.log(`Alice: ${alice.address()}`);
console.log(`Bob: ${bob.address()}`);
console.log("");
// Fund accounts.
await faucetClient.fundAccount(alice.address(), 100_000_000);
await faucetClient.fundAccount(bob.address(), 0);
// Print out initial balances.
console.log("=== Initial Balances ===");
console.log(`Alice: ${await coinClient.checkBalance(alice)}`);
console.log(`Bob: ${await coinClient.checkBalance(bob)}`);
console.log("");
// Have Alice send Bob some AptosCoins. (transfer)
let txnHash = await coinClient.transfer(alice, bob, 1_000, {
gasUnitPrice: BigInt(100)
});
// Waiting for transaction resolution
await client.waitForTransaction(txnHash);
// Print out intermediate balances.
console.log("=== Intermediate Balances ===");
console.log(`Alice: ${await coinClient.checkBalance(alice)}`);
console.log(`Bob: ${await coinClient.checkBalance(bob)}`);
console.log("");
// Have Alice send Bob some more AptosCoins.
txnHash = await coinClient.transfer(alice, bob, 1_000, {
gasUnitPrice: BigInt(100)
});
// Waiting for transaction resolution
await client.waitForTransaction(txnHash, { checkSuccess: true });
// Print out final balances.
console.log("=== Final Balances ===");
console.log(`Alice: ${await coinClient.checkBalance(alice)}`);
console.log(`Bob: ${await coinClient.checkBalance(bob)}`);
console.log("");
})();
ãã®ã¹ã¯ãªãããããŸãå®è¡ããããšæ¬¡ã®ããã«åºåãããŸãã
å®è¡ããŠããå 容ãšããŠã¯ãã¯ã©ã€ã¢ã³ãçšã®ã¢ãžã¥ãŒã«ãèªã¿èŸŒãã§ïŒã€ã®ã¢ã«ãŠã³ããäœæããããŒã¯ã³ãä»äžã転éãããšãã£ãã·ã³ãã«ãªãã®ã§ããethersãªã©ã䜿ã£ãŠãã©ã³ã¶ã¯ã·ã§ã³ãå®è¡ããåŠçãå®è£ ããããšããã人ã§ããã°ãªããšãªãèŠèŠãã®ããèšè¿°ã«ãªã£ãŠãããšæããŸãã
=== Addresses ===
Alice: 0x14b30e5b42a94247c1dd97d4f24d01449cc5e85b02ebcb7fc0281f915fefb963
Bob: 0x121ba4c14d9fba0bc89b201e467771a274547379c03b1bd082abba751c012994
=== Initial Balances ===
Alice: 100000000
Bob: 0
=== Intermediate Balances ===
Alice: 99972800
Bob: 1000
=== Final Balances ===
Alice: 99945600
Bob: 2000
ããŸãããŒã¯ã³ã転éãããŠããããšã確èªã§ããŸãïŒ
Your First NFT
次ã¯ãã®ãããã·ã³ãã«ãªNFTã転éããã¹ã¯ãªããã§ãïŒ
ãã¡ãããã¥ãŒããªã¢ã«ã®æ瀺ã«åŸã£ãŠè³æãåŒã£åŒµã£ãŠããŸãããïŒ
ããã§ã¯ãNFTã®ã¹ããŒãã³ã³ãã©ã¯ãã¯å®è£
ããã«AptosåŽã§çšæããŠãããŠãããã®ãå©çšããŸãïŒ
詳ããäžèº«ãç¥ãããæ¹ã¯äžèšããŒãžãåç
§ããŠã¿ãŠãã ããïŒ
å®è¡ãããµã³ãã«ã¹ã¯ãªããã¯æ¬¡ã®ãããªå 容ã§ãã
import dotenv from "dotenv";
dotenv.config();
import {
AptosClient,
AptosAccount,
FaucetClient,
TokenClient,
CoinClient
} from "aptos";
import {
NODE_URL,
FAUCET_URL
} from "./common";
(async () => {
// Create API and faucet clients.
const client = new AptosClient(NODE_URL);
const faucetClient = new FaucetClient(NODE_URL, FAUCET_URL);
// Create client for working with the token module.
const tokenClient = new TokenClient(client);
// Create a coin client for checking account balances.
const coinClient = new CoinClient(client);
// Create accounts.
const alice = new AptosAccount();
const bob = new AptosAccount();
// Print out account addresses.
console.log("=== Addresses ===");
console.log(`Alice: ${alice.address()}`);
console.log(`Bob: ${bob.address()}`);
console.log("");
// Fund accounts.
await faucetClient.fundAccount(alice.address(), 100_000_000);
await faucetClient.fundAccount(bob.address(), 100_000_000);
console.log("=== Initial Coin Balances ===");
console.log(`Alice: ${await coinClient.checkBalance(alice)}`);
console.log(`Bob: ${await coinClient.checkBalance(bob)}`);
console.log("");
console.log("=== Creating Collection and Token ===");
const collectionName = "Alice's";
const tokenName = "Alice's first token";
const tokenPropertyVersion = 0;
const tokenId = {
token_data_id: {
creator: alice.address().hex(),
collection: collectionName,
name: tokenName,
},
property_version: `${tokenPropertyVersion}`,
};
// Create the collection.
const txnHash1 = await tokenClient.createCollection(
alice,
collectionName,
"Alice's simple collection",
"https://alice.com",
);
// Waiting for transaction resolution
await client.waitForTransaction(txnHash1, {
checkSuccess: true
});
// Create a token in that collection.
const txnHash2 = await tokenClient.createToken(
alice,
collectionName,
tokenName,
"Alice's simple token",
1,
"https://aptos.dev/img/nyan.jpeg",
);
// Waiting for transaction resolution
await client.waitForTransaction(txnHash2, {
checkSuccess: true
});
// get the collection data.
const collectionData = await tokenClient.getCollectionData(alice.address(), collectionName);
console.log(`Alice's collection: ${JSON.stringify(collectionData, null, 4)}`);
// Get the token balance.
const aliceBalance1 = await tokenClient.getToken(
alice.address(),
collectionName,
tokenName,
`${tokenPropertyVersion}`,
);
console.log(`Alice's token balance: ${aliceBalance1["amount"]}`);
// Get the token data.
const tokenData = await tokenClient.getTokenData(
alice.address(),
collectionName,
tokenName
);
console.log(`Alice's token data: ${JSON.stringify(tokenData, null, 4)}`); // <:!:section_8
// Alice offers one token to Bob.
console.log("\n=== Transferring the token to Bob ===");
// transfer
const txnHash3 = await tokenClient.offerToken(
alice,
bob.address(),
alice.address(),
collectionName,
tokenName,
1,
tokenPropertyVersion,
);
// Waiting for transaction resolution
await client.waitForTransaction(txnHash3, {
checkSuccess: true
});
// Bob claims the token Alice offered him.
const txnHash4 = await tokenClient.claimToken(
bob,
alice.address(),
alice.address(),
collectionName,
tokenName,
tokenPropertyVersion,
);
// Waiting for transaction resolution
await client.waitForTransaction(txnHash4, {
checkSuccess: true
});
// get token data
const aliceBalance2 = await tokenClient.getToken(
alice.address(),
collectionName,
tokenName,
`${tokenPropertyVersion}`,
);
// get balance
const bobBalance2 = await tokenClient.getTokenForAccount(bob.address(), tokenId);
console.log(`Alice's token balance: ${aliceBalance2["amount"]}`);
console.log(`Bob's token balance: ${bobBalance2["amount"]}`);
console.log("\n=== Transferring the token back to Alice using MultiAgent ===");
// transfer token
let txnHash5 = await tokenClient.directTransferToken(
bob,
alice,
alice.address(),
collectionName,
tokenName,
1,
tokenPropertyVersion,
);
// Waiting for transaction resolution
await client.waitForTransaction(txnHash5, {
checkSuccess: true
});
// get token data
const aliceBalance3 = await tokenClient.getToken(
alice.address(),
collectionName,
tokenName,
`${tokenPropertyVersion}`,
);
// get balance
const bobBalance3 = await tokenClient.getTokenForAccount(bob.address(), tokenId);
console.log(`Alice's token balance: ${aliceBalance3["amount"]}`);
console.log(`Bob's token balance: ${bobBalance3["amount"]}`);
})();
å ã»ã©ãšåãã§æåã«ã¢ãžã¥ãŒã«ã®ã€ã³ããŒããè¡ã£ãŠãã¢ã«ãŠã³ãã®äœæãNFTã®äœæâ転éãæ®é«ããã§ãã¯ãšããæµãã«ãªã£ãŠããŸãïŒ
泚ç®ãã¹ãã¯ãæåã«èªã¿èŸŒãã§ããtokenClient
ã¢ãžã¥ãŒã«ã§ããã§å®è£
ãããŠããã¡ãœããã䜿ã£ãŠãNFTã®äœæãä»äžã転éãè¡ãããšãã§ããç¹ã§ãïŒ
åé¡ãªãå®è¡ã§ãããšäžèšã®ãããªå 容ãã¿ãŒããã«ã«åºåãããŸãïŒ
=== Addresses ===
Alice: 0x979600b20654944c269abf3ba52d06dfae1d98c74bead66d5ad0d3561d26cd2c
Bob: 0xcfb65b98f4a3277d04e18f864219ae65e28e03c817754a72345ac6d8eaf9bdea
=== Initial Coin Balances ===
Alice: 100000000
Bob: 100000000
=== Creating Collection and Token ===
Alice's collection: {
"description": "Alice's simple collection",
"maximum": "18446744073709551615",
"mutability_config": {
"description": false,
"maximum": false,
"uri": false
},
"name": "Alice's",
"supply": "1",
"uri": "https://alice.com"
}
Alice's token balance: 1
Alice's token data: {
"default_properties": {
"map": {
"data": []
}
},
"description": "Alice's simple token",
"largest_property_version": "0",
"maximum": "18446744073709551615",
"mutability_config": {
"description": false,
"maximum": false,
"properties": false,
"royalty": false,
"uri": false
},
"name": "Alice's first token",
"royalty": {
"payee_address": "0x979600b20654944c269abf3ba52d06dfae1d98c74bead66d5ad0d3561d26cd2c",
"royalty_points_denominator": "0",
"royalty_points_numerator": "0"
},
"supply": "1",
"uri": "https://aptos.dev/img/nyan.jpeg"
}
=== Transferring the token to Bob ===
Alice's token balance: 0
Bob's token balance: 1
=== Transferring the token back to Alice using MultiAgent ===
Alice's token balance: 1
Bob's token balance: 0
Your First Coin
ã¡ãã£ãšé çªãååŸããŸãããdappã ãéãã®ã§æåã«ãã£ã¡ãããŸãšããŠãããŸãïŒïŒ
ãã¥ãŒããªã¢ã«ã«åŸã£ãŠcloneããŠããŸãïŒ
å®è¡ããã¹ã¯ãªããã¯ãmy_coin.ts
ãšãããã®ã§ãïŒ
// Copyright (c) Aptos
// SPDX-License-Identifier: Apache-2.0
import assert from "assert";
import fs from "fs";
import path from "path";
import {
NODE_URL,
FAUCET_URL
} from "./common";
import {
AptosAccount,
AptosClient,
TxnBuilderTypes,
MaybeHexString,
HexString,
FaucetClient
} from "aptos";
import { unstable_deprecatedPropType } from "@mui/utils";
/**
* This example depends on the MoonCoin.move module having already been published to the destination blockchain.
* Open another terminal and `aptos move compile --package-dir ~/aptos-core/aptos-move/move-examples/moon_coin --save-metadata --named-addresses MoonCoin=<Alice address from above step>`.
*/
/**
* readline function
*/
const readline = require("readline").createInterface({
input: process.stdin,
output: process.stdout,
});
/**
* CoinClient class
*/
class CoinClient extends AptosClient {
constructor() {
super(NODE_URL);
}
/**
* registerCoin function
*/
async registerCoin(
coinTypeAddress: HexString,
coinReceiver: AptosAccount
): Promise<string> {
// create Tx data
const rawTxn = await this.generateTransaction(coinReceiver.address(), {
function: "0x1::managed_coin::register",
type_arguments: [`${coinTypeAddress.hex()}::moon_coin::MoonCoin`],
arguments: [],
});
// sign
const bcsTxn = await this.signTransaction(coinReceiver, rawTxn);
// submit
const pendingTxn = await this.submitTransaction(bcsTxn);
return pendingTxn.hash;
}
/**
* Mint function
*/
async mintCoin(
minter: AptosAccount,
receiverAddress: HexString,
amount: number | bigint
): Promise<string> {
// create Tx data
const rawTxn = await this.generateTransaction(minter.address(), {
function: "0x1::managed_coin::mint",
type_arguments: [`${minter.address()}::moon_coin::MoonCoin`],
arguments: [receiverAddress.hex(), amount],
});
// sign
const bcsTxn = await this.signTransaction(minter, rawTxn);
// submit
const pendingTxn = await this.submitTransaction(bcsTxn);
return pendingTxn.hash;
}
/**
* get balance function
*/
async getBalance(
accountAddress: MaybeHexString,
coinTypeAddress: HexString
): Promise<string | number> {
try {
// get balance
const resource = await this.getAccountResource(
accountAddress,
`0x1::coin::CoinStore<${coinTypeAddress.hex()}::moon_coin::MoonCoin>`,
);
return parseInt((resource.data as any)["coin"]["value"]);
} catch (_) {
return 0;
}
}
/**
* transfer function
*/
async transferCoin(
minter: AptosAccount,
receiverAddress: HexString,
amount: number | bigint
): Promise<string> {
// create Tx data
const rawTxn = await this.generateTransaction(minter.address(), {
function: "0x1::coin::transfer",
type_arguments: [`${minter.address()}::moon_coin::MoonCoin`],
arguments: [minter.address().hex(), receiverAddress.hex(), amount],
});
// sign
const bcsTxn = await this.signTransaction(minter, rawTxn);
// submit
const pendingTxn = await this.submitTransaction(bcsTxn);
return pendingTxn.hash;
}
}
/**
* main function
*/
async function main() {
assert(process.argv.length == 3, "Expecting an argument that points to the moon_coin directory.");
// create clinet instance
const client = new CoinClient();
const faucetClient = new FaucetClient(NODE_URL, FAUCET_URL);
// Create two accounts
const alice = new AptosAccount();
const bob = new AptosAccount();
console.log("\n=== Addresses ===");
console.log(`Alice: ${alice.address()}`);
console.log(`Bob: ${bob.address()}`);
await faucetClient.fundAccount(alice.address(), 100_000_000);
await faucetClient.fundAccount(bob.address(), 100_000_000);
await new Promise<void>((resolve) => {
readline.question("Update the module with Alice's address, compile, and press enter.", () => {
resolve();
readline.close();
});
});
// module path ( ../move-example/moon_coin)
const modulePath = process.argv[2];
const packageMetadata = fs.readFileSync(path.join(modulePath, "build", "Examples", "package-metadata.bcs"));
const moduleData = fs.readFileSync(path.join(modulePath, "build", "Examples", "bytecode_modules", "moon_coin.mv"));
console.log("Publishing MoonCoin package.");
// publish module by alice
let txnHash = await client.publishPackage(
alice,
new HexString(packageMetadata.toString("hex")).toUint8Array(),
[
new TxnBuilderTypes.Module(new HexString(moduleData.toString("hex")).toUint8Array()),
]
);
// check transaction status
await client.waitForTransaction(txnHash, { checkSuccess: true });
console.log("Bob registers the newly created coin so he can receive it from Alice");
// call register coin
txnHash = await client.registerCoin(alice.address(), bob);
await client.waitForTransaction(txnHash, { checkSuccess: true });
console.log(`Bob's initial MoonCoin balance: ${await client.getBalance(bob.address(), alice.address())}.`);
console.log("Alice mints Bob some of the new coin.");
// mint coin
txnHash = await client.mintCoin(alice, bob.address(), 100);
await client.waitForTransaction(txnHash, { checkSuccess: true });
console.log(`Bob's updated MoonCoin balance: ${await client.getBalance(bob.address(), alice.address())}.`);
/*
// transfer coin
txnHash = await client.transferCoin(bob, alice.address(), 100);
await client.waitForTransaction(txnHash, { checkSuccess: true });
console.log(`alice's updated MoonCoin balance: ${await client.getBalance(alice.address(), bob.address())}.`);
*/
}
if (require.main === module) {
main().then((resp) => console.log(resp));
}
ã³ã€ã³ãåãåãã¡ãœãããmintããã¡ãœãããæ®é«ã確èªããã¡ãœããã転éããã¡ãœãããå®è£ ãããŠããããããã䜿ã£ãŠmain()ã®äžã§å®è¡ããŠããŸãã
å®è¡ããå
容ãšããŠã¯ãã¢ã«ãŠã³ãã®äœæâš ã¹ãã³ã³ã®ã³ã³ãã€ã«ã»ãããã€â ã³ã€ã³ã®çºè¡ â æ®é«ç¢ºèªãšããæµãã«ãªã£ãŠããŸãã
â» transferã®éšåã¯ãã°ããã£ãŠãŸã åãããŠããŸããã
ãŸãæåã«ã¹ã¯ãªãããå®è¡ãããšæ¬¡ã®ãããªå 容ãåºåãããŸãã
=== Addresses ===
Alice: 0x5cf018f581409a22b93036ba13e4c26a9c2be954f0194ad06b303e6413f4dc93
Bob: 0xe336bc5aa5c060538c5a89a2e039509dad7011be7de67ad1cc88d4dcb0233c17
Update the module with Alice's address, compile, and press enter.
ãããŸã§ãããå¥ã®ã¿ãŒããã«ãç«ã¡äžããŠã¹ãã³ã³ãã³ã³ãã€ã«ã»ãããã€ããŸãïŒ
ãã¥ãŒããªã¢ã«ã®æ瀺ã«åŸã£ãŠãä»åã³ã³ãã€ã«ããMoonCoin.move
ãã¡ã€ã«ãæ ŒçŽãããŠãããã©ã«ãã«ç§»åããMove.toml
ãã¡ã€ã«ããããã©ã«ãé
äžã§ãäžèšã³ãã³ããå®è¡ããŸãããïŒ ã¢ãã¬ã¹ã«ã¯ãäžã§åºåãããŠããAliceã®ã¢ãã¬ã¹ãå
¥ããŠã¿ãŠãã ããïŒïŒ
aptos move compile --named-addresses MoonCoin=<Alice's Address> --save-metadata
ããŸãå®äºãããšäžèšã®ããã«åºåãããŸãïŒ
{
"Result": [
"5cf018f581409a22b93036ba13e4c26a9c2be954f0194ad06b303e6413f4dc93::moon_coin"
]
}
âš Done in 2.60s.
ãããå®äºãããå ã®ã¿ãŒããã«ã«æ»ã£ãŠetnerãæŒããŸãããïŒïŒ ããŒã¯ã³ãçºè¡ãããæ®é«ãååŸã§ããããã«ãªãã¯ãã§ãïŒ
Publishing MoonCoin package.
Bob registers the newly created coin so he can receive it from Alice
Bob's initial MoonCoin balance: 0.
Alice mints Bob some of the new coin.
Bob's updated MoonCoin balance: 100.
undefined
âš Done in 166.96s.
ä»åã³ã³ãã€ã«ããMoonCoin
ã¢ãžã¥ãŒã«ã§ãããaptos_framework
ã®managed_coin
ãç¶æ¿ããŠããMintãªã©ã®é¢æ°ã®å®æ
ã¯ãã£ã¡ã«å®è£
ãããŠããŸããå®æ
ã¯managed_coin.move
ãcoin.move
ãã¡ã€ã«ãåç
§ããŠãã ããã
â» ç§ã絶è³å匷äžã§ãïŒïŒ
ã¡ãªã¿ã«ã³ã³ãã€ã«ããMoveCoin.move
èªäœã¯aptos_framework
ãå©çšããŠãããããã§ãã®ãããã·ã³ãã«ãªã³ãŒãã«ãªã£ãŠããŸãã
/**
* MoonCoin
*/
module MoonCoin::moon_coin {
// Mooncoin
struct MoonCoin {}
/**
* init function
*/
fun init_module(sender: &signer) {
aptos_framework::managed_coin::initialize<MoonCoin>(
sender,
b"Moon Coin",
b"MOON",
6,
false,
);
}
}
Rustãæžããããšããã人ã§ããã°ãèŠèŠãã®ããæ§æã«ãªã£ãŠãããšæããŸãïŒ
ã¡ãªã¿ã«èšå®ãã¡ã€ã«ã¯æ¬¡ã®ãšããã§ãïŒ
[package]
name = "Examples"
version = "0.0.0"
[addresses]
MoonCoin = "_"
[dependencies]
AptosFramework = { local = "../../framework/aptos-framework" }
3. äœã£ãDAppã®æŠèŠ
ããããã¥ãŒããªã¢ã«ã®æåŸã¯ããµã³ãã«Dappã®æ§ç¯ã§ãïŒïŒ
ãã¥ãŒããªã¢ã«ã«åŸã£ãŠãŸãã¯Walletããã©ãŠã¶ã®æ¡åŒµæ©èœã«ã€ã³ã¹ããŒã«ããŸãããïŒ Metamaskãšåããããªæµãã§ãïŒ
ãã³ãã¬ãäœã£ãŠåãããšã確èªããŸãããïŒ
npx create-react-app first-dapp --template typescript
cd first-dapp
npm start
ã¯ã©ã€ã¢ã³ãããAptosäžã®ã¹ããŒãã³ã³ãã©ã¯ããæäœããå Žåã«ã¯ãwindow.aptos
ãšãããªããžã§ã¯ãã«å«ãŸããŠããæ
å ±ã«åŸã£ãŠæäœããŸãã
次ã«ãã¹ããŒãã³ã³ãã©ã¯ãããããã¯ãã§ãŒã³äžã«ãããã€ããŸãããïŒ
ãŸããã¢ã«ãŠã³ããçæããŸãã
aptos init
次ã«ãã¹ããŒãã³ã³ãã©ã¯ããã³ã³ãã€ã«ããŸããã¹ããŒãã³ã³ãã©ã¯ãã®ãããã©ã«ããŸã§ã®ãã¹ãšã¢ãã¬ã¹ã®æ å ±ã¯å人ã®ç°å¢ã«åãããã«é©å®å€æŽããŠããŸãã
aptos move compile --package-dir ./../move-example/hello_blockchain/ --named-addresses hello_blockchain=0xa7bea4f79092c5f315e4ddf40af2637ace9e0438d22e64587bd3bfcb5ea9c647
ã³ã³ãã€ã«çµæ
{
"Result": [
"a7bea4f79092c5f315e4ddf40af2637ace9e0438d22e64587bd3bfcb5ea9c647::message"
]
}
次ã«ã¹ããŒãã³ã³ãã©ã¯ãã®ãã¹ããå®è¡ããŸãã
aptos move test --package-dir ./../move-example/hello_blockchain/ --named-addresses hello_blockchain=0xa7bea4f79092c5f315e4ddf40af2637ace9e0438d22e64587bd3bfcb5ea9c647
ãã¹ãçµæ
INCLUDING DEPENDENCY AptosFramework
INCLUDING DEPENDENCY AptosStdlib
INCLUDING DEPENDENCY MoveStdlib
BUILDING Examples
Running Move unit tests
[ PASS ] 0xa7bea4f79092c5f315e4ddf40af2637ace9e0438d22e64587bd3bfcb5ea9c647::message_tests::sender_can_set_message
[ PASS ] 0xa7bea4f79092c5f315e4ddf40af2637ace9e0438d22e64587bd3bfcb5ea9c647::message::sender_can_set_message
Test result: OK. Total tests: 2; passed: 2; failed: 0
{
"Result": "Success"
}
ãããŠã¹ããŒãã³ã³ãã©ã¯ãããããã€ããŸãã
aptos move publish --package-dir ./../move-example/hello_blockchain/ --named-addresses hello_blockchain=0xa7bea4f79092c5f315e4ddf40af2637ace9e0438d22e64587bd3bfcb5ea9c647
ãããã€ãå®äºããããnpm run start
ã§ããã³ããšã³ãåŽã®ã¢ããªãç«ã¡äžããŸãããïŒ
å
容ãšããŠã¯è³ã£ãŠã·ã³ãã«ã§messageã®settterãšgetteræ©èœãè©Šãããšãã§ããŸãïŒïŒ
CSSãæäœéã®ãã®ã«ãªã£ãŠããã®ã§éåžžã«ã·ã³ãã«ã§ãïŒïŒ
4. ãœãŒã¹ã³ãŒããªã©
ä»å䜿çšããã¹ããŒãã³ã³ãã©ã¯ãã¯äžèšãã©ã«ãã«ååšããŸãã
å®éã®ãœãŒã¹ã³ãŒãã§ãã
module hello_blockchain::message {
use std::error;
use std::signer;
use std::string;
use aptos_framework::account;
use aptos_std::event;
// MessageHolder
struct MessageHolder has key {
message: string::String,
message_change_events: event::EventHandle<MessageChangeEvent>,
}
// MessageChangeEvent
struct MessageChangeEvent has drop, store {
from_message: string::String,
to_message: string::String,
}
/// There is no message present
const ENO_MESSAGE: u64 = 0;
/**
* get_message function
*/
public fun get_message(addr: address): string::String acquires MessageHolder {
assert!(exists<MessageHolder>(addr), error::not_found(ENO_MESSAGE));
*&borrow_global<MessageHolder>(addr).message
}
/**
* set_message function
*/
public entry fun set_message(account: signer, message: string::String)
acquires MessageHolder {
// get signer address
let account_addr = signer::address_of(&account);
if (!exists<MessageHolder>(account_addr)) {
move_to(&account, MessageHolder {
message,
message_change_events: account::new_event_handle<MessageChangeEvent>(&account),
})
} else {
let old_message_holder = borrow_global_mut<MessageHolder>(account_addr);
let from_message = *&old_message_holder.message;
event::emit_event(&mut old_message_holder.message_change_events, MessageChangeEvent {
from_message,
to_message: copy message,
});
old_message_holder.message = message;
}
}
#[test(account = @0x1)]
public entry fun sender_can_set_message(account: signer) acquires MessageHolder {
let addr = signer::address_of(&account);
aptos_framework::account::create_account_for_test(addr);
set_message(account, string::utf8(b"Hello, Blockchain"));
assert!(
get_message(addr) == string::utf8(b"Hello, Blockchain"),
ENO_MESSAGE
);
}
}
ããã³ãåŽã§ã¯ethereumãªããžã§ã¯ãã䜿ã£ãŠã¢ã¯ã»ã¹ãããšåããããªæèŠã§ç¹ããŸãïŒïŒ
ã¢ãã¬ã¹æ å ±ãååŸããæ¹æ³
/**
* init function
*/
const init = async() => {
// connect
await window.aptos.connect();
const data = await window.aptos.account();
// set address
setAddress(data.address);
}
ã¹ããŒãã³ã³ãã©ã¯ãäžã®ã¡ãœãããæäœããéã®ã¡ãœãã
const handleSubmit = async (e: any) => {
e.preventDefault();
if (!ref.current) return;
// get value
// const message = ref.current.value;
// tx data
const transaction = {
type: "entry_function_payload",
function: `${address}::message::set_message`,
arguments: [stringToHex(text)],
type_arguments: [],
};
try {
setIsSaving(true);
// call signAndSubmitTransaction function
await window.aptos.signAndSubmitTransaction(transaction);
alert('send success')
} catch(e) {
alert('send fail...');
} finally {
setIsSaving(false);
}
}
ãœãŒã¹ã³ãŒãã®ç°¡åãªå
±æã¯ä»¥äžã§ãïŒ
ä»ã«ãã¢ããªãäœãããã«ã¯ãRustãšMoveã§ãã£ãšèšç·Žããªããšãããªããã§ãã»ã»ã»ã
5. ãã®ä»Aptosäžã«å±éãããŠããæ°ã«ãªã£ããããã¯ã
代衚çãªãããã¯ããšããŠã¯äžèšã®3ç¹ãæãããããšæããŸãïŒ
Bluemove
Ethereumã§èšããšãããOpenseaãšèšãã°åãããããã§ãããããSuiäžã§å±éãããŠããNFTãªã©ãã¿ãããšãã§ããŸãïŒïŒ
Aptos Name Service
ENSã®Aptosçãšèšãã°ã€ã¡ãŒãžãããããšæããŸãïŒ!ã¢ãã¬ã¹ãšä»»æã®ãã¡ã€ã³ãçŽã¥ããããšãã§ããŸãïŒïŒ
Aptos passport
ã€ãæè¿ç¥ã£ãã®ã§ãããããªãããã¯ããåºãŠããããã§ãïŒ ãã¡ã€ã³ç»é²æ©èœã®ä»ãããŒã¯ã³ã®Rewardæ©èœãªã©ããããŸãïŒ
6. æåŸã«
ç§å¯éµãããŒããŒã·ã§ã³ãããæ©èœã ã£ãããMoveèšèªã ã£ããè²ã æè¡çã«é¢çœããšããããããããã¯ãã§ãŒã³ãããžã§ã¯ãã§ã¯ãããŸãããã¡ã€ã³ãããã®ãªãªãŒã¹ã«ã€ããŠã¯PRã匱ãã£ãããããã¿ã€ãã³ã°ãç¥ããªãã£ãæ¹ãå€ãã£ãããã§ãã©ãã«ããã£ãããã§ãã
äžèšã®èšäºã«ããã¬ãã£ããªå 容ãèšèŒãããŠããã®ã§å è¡ããå°ãäžå®ã§ãã©ã€ãã«ã§ããSuiã«ã©ã®ããã«åœ±é¿ããŠãããã¯ãŠã©ããããå¿ èŠããããšæããŸããïŒ
Suiã¯ããã¹ãããããããŒã³ãããŠãããå°çšã®ãŠã©ã¬ãããã€ã³ã¹ããŒã«ããã°ãã¹ããããçšã®ããŒã¯ã³ããããããšãã£ãç¶æ ã«ãªã£ãŠããŸãã
ä»åã¯ãããŸã§ãšããããšæããŸãïŒ
Aptosã«ã€ããŠã¯AptosJapanãšããçµç¹ããããå匷äŒãªã©ãéå¬ããŠãããŠããã®ã§ããã«ç¥ãããæ¹ã¯connpassã«ç»é²ããŠã€ãã³ããªã©ã«åå ãããšè¯ãããã§ãïŒ
æåŸãŸã§èªãã§ããã ãããããšãããããŸããïŒïŒ
åèæç®
- Aptos Developer Docs
- ãä»®æ³é貚ãAptos(ã¢ããã¹)ãšã¯ïŒä»åŸã®èŠéããå°æ¥æ§ã培åºè§£èª¬ïŒ
- Aptos OfficialSite
- Martian
- 話é¡ã®L1ãã§ãŒã³ãAptosããšã¯ïŒæŠèŠãç¹åŸŽã培åºè§£èª¬ã480åå調éæžã
- liquidswap
- liquidswap App
- Aptos Explorer
- White Paper
- Aptos Faucet
- install-aptos-cli
- éçºå ãæªç¢ºèªã®Macã¢ããªã±ãŒã·ã§ã³ãéã
- Discussion Forum
- aptos-core
- The Move Book
- Blue Wallet
- AptosïŒæåŸ å€§ããã«èœèã倧ããã£ããããã¯ãã§ãŒã³ã®èªç
- movemarketcap
- è«æ翻蚳: HotStuff: BFT Consensus in the Lens of Blockchain
Discussion