Skip to content

Commit

Permalink
feat: replaced println with console.log in live code examples (#2999)
Browse files Browse the repository at this point in the history
* feat: replaced println with console.log in live code examples

* refactor: simplified logic of console.log function in live code
  • Loading branch information
hui-an-yang authored Jun 20, 2024
1 parent beb89a3 commit 166ffdb
Show file tree
Hide file tree
Showing 144 changed files with 5,872 additions and 5,855 deletions.
1 change: 0 additions & 1 deletion cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
"preendorsements",
"prevalidated",
"prevalidation",
"println",
"Protofire",
"ProxfordY",
"PtNairobi",
Expand Down
22 changes: 11 additions & 11 deletions docs/complex_parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ importKey(Tezos, secretKey)
validators : validatorsMap
}})
}).then((contractOriginated) => {
println(`Waiting for confirmation of origination for ${contractOriginated.contractAddress}...`);
console.log(`Waiting for confirmation of origination for ${contractOriginated.contractAddress}...`);
return contractOriginated.contract();
}).then((contract) => {
println(`Origination completed.`);
}).catch((error) => println(`Error: ${JSON.stringify(error, null, 2)}`));
console.log(`Origination completed.`);
}).catch((error) => console.log(`Error: ${JSON.stringify(error, null, 2)}`));
```

## Calling the function of a contract having a complex object as a parameter
Expand Down Expand Up @@ -145,8 +145,8 @@ importKey(Tezos, secretKey)
owner: 'tz1PgQt52JMirBUhhkq1eanX8hVd1Fsg71Lr',
parent: 'FFFF',
ttl: { Some: '10' }}).toTransferParams();
println(JSON.stringify(inspect, null, 2))
}).catch(error => println(`Error: ${JSON.stringify(error, null, 2)}`));
console.log(JSON.stringify(inspect, null, 2))
}).catch(error => console.log(`Error: ${JSON.stringify(error, null, 2)}`));
```

#### Call the set_child_record function when all the arguments are defined
Expand All @@ -172,11 +172,11 @@ importKey(Tezos, secretKey)
ttl: { Some: '10' }
}).send();
}).then(op => {
println(`Waiting for ${op.hash} to be confirmed...`);
console.log(`Waiting for ${op.hash} to be confirmed...`);
return op.confirmation(1).then(() => op.hash);
}).then(hash => {
println(`Operation injected: https://better-call.dev/ghostnet/KT1B2exfRrGMjfZqWK1bDemr3nBFhHsUWQuN/operations`);
}).catch(error => println(`Error: ${JSON.stringify(error, null, 2)}`));
console.log(`Operation injected: https://better-call.dev/ghostnet/KT1B2exfRrGMjfZqWK1bDemr3nBFhHsUWQuN/operations`);
}).catch(error => console.log(`Error: ${JSON.stringify(error, null, 2)}`));
```
#### Call the set_child_record function when optional arguments are null

Expand All @@ -203,9 +203,9 @@ importKey(Tezos, secretKey)
ttl: null
}).send();
}).then(op => {
println(`Waiting for ${op.hash} to be confirmed...`);
console.log(`Waiting for ${op.hash} to be confirmed...`);
return op.confirmation(1).then(() => op.hash);
}).then(hash => {
println(`Operation injected: https://better-call.dev/ghostnet/KT1B2exfRrGMjfZqWK1bDemr3nBFhHsUWQuN/operations`);
}).catch(error => println(`Error: ${JSON.stringify(error, null, 2)}`));
console.log(`Operation injected: https://better-call.dev/ghostnet/KT1B2exfRrGMjfZqWK1bDemr3nBFhHsUWQuN/operations`);
}).catch(error => console.log(`Error: ${JSON.stringify(error, null, 2)}`));
```
6 changes: 3 additions & 3 deletions docs/contract-test-collection.md
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ Tezos.contract
0: '1', //nat
1: 'tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx', //address
});
println(`The value associated with the specified key of the map is ${valueMap}.`);
console.log(`The value associated with the specified key of the map is ${valueMap}.`);
return myContract.storage();
})

Expand All @@ -506,10 +506,10 @@ Tezos.contract
});
})
.then((valueBigMap) => {
println(`The value associated with the specified key of the bigMap is ${valueBigMap}.`);
console.log(`The value associated with the specified key of the bigMap is ${valueBigMap}.`);
});
})
.catch((error) => println(`Error: ${JSON.stringify(error, null, 2)}`));
.catch((error) => console.log(`Error: ${JSON.stringify(error, null, 2)}`));
```

</TabItem>
Expand Down
30 changes: 15 additions & 15 deletions docs/drain_account.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Tezos.signer
.publicKeyHash()
.then((address) => {
Tezos.tz.getBalance(address).then((balance) => {
println(
console.log(
`The account we want to drain is ${address}.\nIts initial balance is ${
balance.toNumber() / 1000000
} ꜩ.`
Expand All @@ -44,7 +44,7 @@ Tezos.signer
const maxAmount = balance.minus(
estimate.suggestedFeeMutez + getRevealFee(address)
).toNumber();
println(
console.log(
`The estimated fees related to the emptying operation are ${
estimate.suggestedFeeMutez
} mutez.\nThe fees related to the reveal operation are ${
Expand All @@ -63,19 +63,19 @@ Tezos.signer
});
})
.then((op) => {
println(`Waiting for confirmation of the draining operation...`);
console.log(`Waiting for confirmation of the draining operation...`);
return op.confirmation(1).then(() => op.hash);
})
.then((hash) => {
println(`The account has been emptied.`);
console.log(`The account has been emptied.`);
return Tezos.tz.getBalance(address);
})
.then((finalBalance) => {
println(`The balance is now ${finalBalance.toNumber() / 1000000} ꜩ.`);
console.log(`The balance is now ${finalBalance.toNumber() / 1000000} ꜩ.`);
});
});
})
.catch((error) => println(`Error: ${JSON.stringify(error, null, 2)}`));
.catch((error) => console.log(`Error: ${JSON.stringify(error, null, 2)}`));
```

## Draining originated accounts (KT1)
Expand Down Expand Up @@ -118,43 +118,43 @@ Tezos.signer
init: { string: address },
})
.then((contractOrigination) => {
println(
console.log(
`Waiting for confirmation of origination for ${contractOrigination.contractAddress}...`
);
return contractOrigination.contract();
})
.then((contract) => {
println(`Origination completed.`);
console.log(`Origination completed.`);
Tezos.tz.getBalance(contract.address).then((balance) => {
println(`The balance of the contract is ${balance.toNumber() / 1000000} ꜩ.`);
console.log(`The balance of the contract is ${balance.toNumber() / 1000000} ꜩ.`);
const estimateOp = contract.methodsObject
.do(transferImplicit('tz1PgQt52JMirBUhhkq1eanX8hVd1Fsg71Lr', balance.toNumber()))
.toTransferParams({});
println(`Waiting for the estimation of the smart contract call...`);
console.log(`Waiting for the estimation of the smart contract call...`);
Tezos.estimate
.transfer(estimateOp)
.then((estimate) => {
//Will be deducted from manager's address
println(
console.log(
`The estimated fees related to the emptying operation are ${estimate.suggestedFeeMutez} mutez.`
);
return contract.methodsObject
.do(transferImplicit('tz1PgQt52JMirBUhhkq1eanX8hVd1Fsg71Lr', balance.toNumber()))
.send({ amount: 0 });
})
.then((operation) => {
println(`Waiting for confirmation of the draining operation...`);
console.log(`Waiting for confirmation of the draining operation...`);
return operation.confirmation(1).then(() => operation.hash);
})
.then((hash) => {
println(`The account has been emptied.`);
console.log(`The account has been emptied.`);
return Tezos.tz.getBalance(contract.address);
})
.then((finalBalance) => {
println(`The balance is now ${finalBalance.toNumber() / 1000000} ꜩ.`);
console.log(`The balance is now ${finalBalance.toNumber() / 1000000} ꜩ.`);
});
});
});
})
.catch((error) => println(`Error: ${JSON.stringify(error, null, 2)}`));
.catch((error) => console.log(`Error: ${JSON.stringify(error, null, 2)}`));
```
28 changes: 14 additions & 14 deletions docs/estimate.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ values={[
const amount = 2;
const address = 'tz1h3rQ8wBxFd8L9B3d7Jhaawu6Z568XU3xY';

println(`Estimating the transfer of ${amount} ꜩ to ${address} : `);
console.log(`Estimating the transfer of ${amount} ꜩ to ${address} : `);
Tezos.estimate
.transfer({ to: address, amount: amount })
.then((est) => {
println(`burnFeeMutez : ${est.burnFeeMutez},
console.log(`burnFeeMutez : ${est.burnFeeMutez},
gasLimit : ${est.gasLimit},
minimalFeeMutez : ${est.minimalFeeMutez},
storageLimit : ${est.storageLimit},
Expand All @@ -73,11 +73,11 @@ Tezos.estimate
const amount = 2;
const address = 'tz1h3rQ8wBxFd8L9B3d7Jhaawu6Z568XU3xY';

println(`Estimating the transfer of ${amount} ꜩ to ${address} : `);
console.log(`Estimating the transfer of ${amount} ꜩ to ${address} : `);
Tezos.estimate
.transfer({ to: address, amount: amount })
.then((est) => {
println(`burnFeeMutez : ${est.burnFeeMutez},
console.log(`burnFeeMutez : ${est.burnFeeMutez},
gasLimit : ${est.gasLimit},
minimalFeeMutez : ${est.minimalFeeMutez},
storageLimit : ${est.storageLimit},
Expand Down Expand Up @@ -116,11 +116,11 @@ Tezos.contract
return contract.methodsObject.increment(7);
})
.then((op) => {
println(`Estimating the smart contract call: `);
console.log(`Estimating the smart contract call: `);
return Tezos.estimate.contractCall(op);
})
.then((estimate) => {
println(`burnFeeMutez : ${estimate.burnFeeMutez},
console.log(`burnFeeMutez : ${estimate.burnFeeMutez},
gasLimit : ${estimate.gasLimit},
minimalFeeMutez : ${estimate.minimalFeeMutez},
storageLimit : ${estimate.storageLimit},
Expand All @@ -145,11 +145,11 @@ Tezos.wallet
return contract.methodsObject.increment(7);
})
.then((op) => {
println(`Estimating the smart contract call: `);
console.log(`Estimating the smart contract call: `);
return Tezos.estimate.contractCall(op);
})
.then((estimate) => {
println(`burnFeeMutez : ${estimate.burnFeeMutez},
console.log(`burnFeeMutez : ${estimate.burnFeeMutez},
gasLimit : ${estimate.gasLimit},
minimalFeeMutez : ${estimate.minimalFeeMutez},
storageLimit : ${estimate.storageLimit},
Expand Down Expand Up @@ -180,7 +180,7 @@ values={[
// import { TezosToolkit } from '@taquito/taquito';
// const Tezos = new TezosToolkit('https://ghostnet.ecadinfra.com');

println(`Estimating the contract origination : `);
console.log(`Estimating the contract origination : `);
Tezos.estimate
.originate({
code: genericMultisigJSONfile,
Expand All @@ -191,15 +191,15 @@ Tezos.estimate
},
})
.then((originationOp) => {
println(`burnFeeMutez : ${originationOp.burnFeeMutez},
console.log(`burnFeeMutez : ${originationOp.burnFeeMutez},
gasLimit : ${originationOp.gasLimit},
minimalFeeMutez : ${originationOp.minimalFeeMutez},
storageLimit : ${originationOp.storageLimit},
suggestedFeeMutez : ${originationOp.suggestedFeeMutez},
totalCost : ${originationOp.totalCost},
usingBaseFeeMutez : ${originationOp.usingBaseFeeMutez}`);
})
.catch((error) => println(`Error: ${JSON.stringify(error, null, 2)}`));
.catch((error) => console.log(`Error: ${JSON.stringify(error, null, 2)}`));
```

</TabItem>
Expand All @@ -210,7 +210,7 @@ Tezos.estimate
// import { TezosToolkit } from '@taquito/taquito';
// const Tezos = new TezosToolkit('https://ghostnet.ecadinfra.com');

println(`Estimating the contract origination : `);
console.log(`Estimating the contract origination : `);
Tezos.estimate
.originate({
code: genericMultisigJSONfile,
Expand All @@ -221,15 +221,15 @@ Tezos.estimate
},
})
.then((originationOp) => {
println(`burnFeeMutez : ${originationOp.burnFeeMutez},
console.log(`burnFeeMutez : ${originationOp.burnFeeMutez},
gasLimit : ${originationOp.gasLimit},
minimalFeeMutez : ${originationOp.minimalFeeMutez},
storageLimit : ${originationOp.storageLimit},
suggestedFeeMutez : ${originationOp.suggestedFeeMutez},
totalCost : ${originationOp.totalCost},
usingBaseFeeMutez : ${originationOp.usingBaseFeeMutez}`);
})
.catch((error) => println(`Error: ${JSON.stringify(error, null, 2)}`));
.catch((error) => console.log(`Error: ${JSON.stringify(error, null, 2)}`));
```

</TabItem>
Expand Down
34 changes: 17 additions & 17 deletions docs/inmemory_signer.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ InMemorySigner.fromSecretKey('edsk2rKA8YEExg9Zo2qNPiQnnYheF1DhqjLVmfKdxiFfu5GyGR
return Tezos.signer.publicKeyHash();
})
.then((publicKeyHash) => {
println(`The public key hash associated is: ${publicKeyHash}.`);
console.log(`The public key hash associated is: ${publicKeyHash}.`);
})
.catch((error) => println(`Error: ${error} ${JSON.stringify(error, null, 2)}`));
.catch((error) => console.log(`Error: ${error} ${JSON.stringify(error, null, 2)}`));
```

```js live noInline
Expand All @@ -67,9 +67,9 @@ InMemorySigner.fromSecretKey('spsk2Fiz7sGP5fNMJrokp6ynTa4bcFbsRhw58FHXbNf5ProDNF
return Tezos.signer.publicKeyHash();
})
.then((publicKeyHash) => {
println(`The public key hash associated is: ${publicKeyHash}.`);
console.log(`The public key hash associated is: ${publicKeyHash}.`);
})
.catch((error) => println(`Error: ${error} ${JSON.stringify(error, null, 2)}`));
.catch((error) => console.log(`Error: ${error} ${JSON.stringify(error, null, 2)}`));
```

When required, Taquito offers the `b58cencode` function allowing to encode the secret in base58. The parameters of the function are the secret, that can be a `hex string` or an `Uint8Array`, and the desired prefix. Here is an example with a `hex string`:
Expand All @@ -84,7 +84,7 @@ const b58encodedSecret = b58cencode(
'7c842c15c8b0c8fd228e6cb5302a50201f41642dd36b699003fb3c857920bc9d',
prefix[Prefix.P2SK]
);
println(
console.log(
`The secret is encoded in base58 and the prefix "p2sk" is added to it: ${b58encodedSecret}.`
);
//We take the encoded secret to configure the signer.
Expand All @@ -95,9 +95,9 @@ InMemorySigner.fromSecretKey(b58encodedSecret)
return Tezos.signer.publicKeyHash();
})
.then((publicKeyHash) => {
println(`The public key hash associated is: ${publicKeyHash}.`);
console.log(`The public key hash associated is: ${publicKeyHash}.`);
})
.catch((error) => println(`Error: ${error} ${JSON.stringify(error, null, 2)}`));
.catch((error) => console.log(`Error: ${error} ${JSON.stringify(error, null, 2)}`));
```

### Loading an encrypted private key with a passphrase
Expand Down Expand Up @@ -131,9 +131,9 @@ InMemorySigner.fromSecretKey(
return Tezos.signer.publicKeyHash();
})
.then((publicKeyHash) => {
println(`The public key hash associated is: ${publicKeyHash}.`);
console.log(`The public key hash associated is: ${publicKeyHash}.`);
})
.catch((error) => println(`Error: ${error} ${JSON.stringify(error, null, 2)}`));
.catch((error) => console.log(`Error: ${error} ${JSON.stringify(error, null, 2)}`));
```

```js live noInline
Expand All @@ -151,9 +151,9 @@ InMemorySigner.fromSecretKey(
return Tezos.signer.publicKeyHash();
})
.then((publicKeyHash) => {
println(`The public key hash associated is: ${publicKeyHash}.`);
console.log(`The public key hash associated is: ${publicKeyHash}.`);
})
.catch((error) => println(`Error: ${error} ${JSON.stringify(error, null, 2)}`));
.catch((error) => console.log(`Error: ${error} ${JSON.stringify(error, null, 2)}`));
```

```js live noInline
Expand All @@ -171,9 +171,9 @@ InMemorySigner.fromSecretKey(
return Tezos.signer.publicKeyHash();
})
.then((publicKeyHash) => {
println(`The public key hash associated is: ${publicKeyHash}.`);
console.log(`The public key hash associated is: ${publicKeyHash}.`);
})
.catch((error) => println(`Error: ${error} ${JSON.stringify(error, null, 2)}`));
.catch((error) => console.log(`Error: ${error} ${JSON.stringify(error, null, 2)}`));
```


Expand Down Expand Up @@ -202,9 +202,9 @@ With ed25519 default derivation path (Reminder Must be hardened with either h or
Tezos.setSignerProvider(signer)
Tezos.signer.publicKeyHash()
.then((publicKeyHash) => {
println(`The public key hash associated is: ${publicKeyHash}`)
console.log(`The public key hash associated is: ${publicKeyHash}`)
})
.catch(err => println(err))
.catch(err => console.log(err))
```

With a non-default derivation path non-hardened with a tz2 address
Expand All @@ -225,9 +225,9 @@ With a non-default derivation path non-hardened with a tz2 address
Tezos.setSignerProvider(signer)
Tezos.signer.publicKeyHash()
.then((publicKeyHash) => {
println(`The public key hash associated is: ${publicKeyHash}`)
console.log(`The public key hash associated is: ${publicKeyHash}`)
})
.catch(err => println(err))
.catch(err => console.log(err))
```

### Using a testnet faucet key
Expand Down
Loading

0 comments on commit 166ffdb

Please sign in to comment.