Skip to content

Commit

Permalink
Merge pull request #39 from krau5/main
Browse files Browse the repository at this point in the history
Update guide for writing first smart contract with Blueprint SDK
  • Loading branch information
SwiftAdviser authored Oct 5, 2023
2 parents 8f334c2 + 1bb54fb commit 7898d24
Show file tree
Hide file tree
Showing 10 changed files with 280 additions and 383 deletions.
113 changes: 46 additions & 67 deletions 02-contract/index.md

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions 02-contract/test/counter.fc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "imports/stdlib.fc";

;; =============== storage =============================

(int) load_data() inline {
Expand All @@ -14,8 +16,8 @@
;; =============== messages =============================

() recv_internal(int msg_value, cell in_msg, slice in_msg_body) impure {
if (in_msg_body.slice_empty?()) {
return ();
if (in_msg_body.slice_empty?()) {
return ();
}
int op = in_msg_body~load_uint(32);
var (counter) = load_data();
Expand All @@ -29,4 +31,4 @@
int counter() method_id {
var (counter) = load_data();
return counter;
}
}
10 changes: 4 additions & 6 deletions 02-contract/test/deploy.step8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { mnemonicToWalletKey } from "ton-crypto";
import { TonClient, Cell, WalletContractV4 } from "ton";
import Counter from "./counter.step7"; // this is the interface class from step 7

async function deploy() {
export async function run() {
// initialize ton rpc client on testnet
const endpoint = await getHttpEndpoint({ network: "testnet" });
const client = new TonClient({ endpoint });
Expand All @@ -17,7 +17,7 @@ async function deploy() {
const counterCode = Cell.fromBoc(fs.readFileSync("counter.cell"))[0]; // compilation output from step 6
const initialCounterValue = Date.now(); // to avoid collisions use current number of milliseconds since epoch as initial value
const counter = Counter.createForDeploy(counterCode, initialCounterValue);

// exit if contract is already deployed
console.log("contract address:", counter.address.toString());
if (await client.isContractDeployed(counter.address)) {
Expand All @@ -36,7 +36,7 @@ async function deploy() {
const walletContract = client.open(wallet);
const walletSender = walletContract.sender(key.secretKey);
const seqno = await walletContract.getSeqno();

// send the deploy transaction
const counterContract = client.open(counter);
await counterContract.sendDeploy(walletSender);
Expand All @@ -51,8 +51,6 @@ async function deploy() {
console.log("deploy transaction confirmed!");
}

deploy();

function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
}
4 changes: 1 addition & 3 deletions 02-contract/test/step9.ts → 02-contract/test/getCounter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getHttpEndpoint } from "@orbs-network/ton-access";
import { TonClient, Address } from "ton";
import Counter from "./counter.step9"; // this is the interface class we just implemented

async function main() {
export async function run() {
// initialize ton rpc client on testnet
const endpoint = await getHttpEndpoint({ network: "testnet" });
const client = new TonClient({ endpoint });
Expand All @@ -21,5 +21,3 @@ async function main() {
//console.log("value:", counterValue.toString());
console.log("value:", counterValue >= 1000000000000n ? "more than 1T" : "less than 1T");
}

main();
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { mnemonicToWalletKey } from "ton-crypto";
import { TonClient, WalletContractV4, Address } from "ton";
import Counter from "./counter.step10"; // this is the interface class we just implemented

async function main() {
export async function run() {
// initialize ton rpc client on testnet
const endpoint = await getHttpEndpoint({ network: "testnet" });
const client = new TonClient({ endpoint });
Expand Down Expand Up @@ -43,8 +43,6 @@ async function main() {
console.log("transaction confirmed!");
}

main();

function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
}
168 changes: 72 additions & 96 deletions docs/02-contract/index.html

Large diffs are not rendered by default.

84 changes: 36 additions & 48 deletions docs/02-contract/mainnet-npmton.html

Large diffs are not rendered by default.

93 changes: 39 additions & 54 deletions docs/02-contract/mainnet-npmton.md

Large diffs are not rendered by default.

84 changes: 36 additions & 48 deletions docs/02-contract/testnet-npmton.html

Large diffs are not rendered by default.

93 changes: 39 additions & 54 deletions docs/02-contract/testnet-npmton.md

Large diffs are not rendered by default.

0 comments on commit 7898d24

Please sign in to comment.