Skip to content

Commit

Permalink
Merge branch 'master' into guides-update
Browse files Browse the repository at this point in the history
  • Loading branch information
ihsraham committed Oct 17, 2023
2 parents 7670420 + 80c0bc9 commit 8beba59
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 32 deletions.
38 changes: 26 additions & 12 deletions src/common/docs/_smart-contract-solidity-read.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@ import Tabs from "@theme/Tabs";

// web3 is const web3 = new Web3(web3authProvider); from above.

// Get user's Ethereum public address
const fromAddress = (await web3.eth.getAccounts())[0];

const contractABI =
'[{"inputs":[{"internalType":"string","name":"initMessage","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"string","name":"newMessage","type":"string"}],"name":"update","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"message","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"}]';
const contractAddress = "0xD65AF91Bbb4334711A598dFD293596E6dc2d8313#code";
const contract = new web3.eth.Contract(JSON.parse(contractABI), contractAddress);
const contractABI = [
{ inputs: [{ internalType: "string", name: "initMessage", type: "string" }], stateMutability: "nonpayable", type: "constructor" },
{ inputs: [], name: "message", outputs: [{ internalType: "string", name: "", type: "string" }], stateMutability: "view", type: "function" },
{
inputs: [{ internalType: "string", name: "newMessage", type: "string" }],
name: "update",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
];
const contractAddress = "0x04cA407965D60C2B39d892a1DFB1d1d9C30d0334";
const contract = new web3.eth.Contract(JSON.parse(JSON.stringify(contractABI)), contractAddress);

// Read message from smart contract
const message = await contract.methods.message().call();
Expand All @@ -41,11 +47,19 @@ const message = await contract.methods.message().call();

const signer = provider.getSigner();

const contractABI =
'[{"inputs":[{"internalType":"string","name":"initMessage","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"string","name":"newMessage","type":"string"}],"name":"update","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"message","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"}]';
const contractAddress = "0xD65AF91Bbb4334711A598dFD293596E6dc2d8313#code";

const contract = new ethers.Contract(contractAddress, contractABI, signer);
const contractABI = [
{ inputs: [{ internalType: "string", name: "initMessage", type: "string" }], stateMutability: "nonpayable", type: "constructor" },
{ inputs: [], name: "message", outputs: [{ internalType: "string", name: "", type: "string" }], stateMutability: "view", type: "function" },
{
inputs: [{ internalType: "string", name: "newMessage", type: "string" }],
name: "update",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
];
const contractAddress = "0x04cA407965D60C2B39d892a1DFB1d1d9C30d0334";
const contract = new ethers.Contract(contractAddress, JSON.parse(JSON.stringify(contractABI)), signer);

// Read message from smart contract
const message = await contract.message();
Expand Down
50 changes: 33 additions & 17 deletions src/common/docs/_smart-contract-solidity-write.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,26 @@ import Tabs from "@theme/Tabs";

// web3 is const web3 = new Web3(web3authProvider); from above.

// Get user's Ethereum public address
const fromAddress = (await web3.eth.getAccounts())[0];

const contractABI =
'[{"inputs":[{"internalType":"string","name":"initMessage","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"string","name":"newMessage","type":"string"}],"name":"update","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"message","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"}]';
const contractAddress = "0xD65AF91Bbb4334711A598dFD293596E6dc2d8313#code";
const contract = new web3.eth.Contract(JSON.parse(contractABI), contractAddress);

// Send transaction to smart contract to update message and wait to finish
const receipt = await contract.methods.update("NEW_MESSAGE").send({
from: fromAddress,
maxPriorityFeePerGas: "5000000000", // Max priority fee per gas
maxFeePerGas: "6000000000000", // Max fee per gas
const contractABI = [
{ inputs: [{ internalType: "string", name: "initMessage", type: "string" }], stateMutability: "nonpayable", type: "constructor" },
{ inputs: [], name: "message", outputs: [{ internalType: "string", name: "", type: "string" }], stateMutability: "view", type: "function" },
{
inputs: [{ internalType: "string", name: "newMessage", type: "string" }],
name: "update",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
];
const contractAddress = "0x04cA407965D60C2B39d892a1DFB1d1d9C30d0334";
const contract = new web3.eth.Contract(JSON.parse(JSON.stringify(contractABI)), contractAddress);

// Write message to smart contract
// @ts-ignore
const receipt = await contract.methods.update("W3A").send({
from: (await web3.eth.getAccounts())[0],
maxFeePerGas: "300",
maxPriorityFeePerGas: "10",
});
```

Expand All @@ -45,10 +52,19 @@ const receipt = await contract.methods.update("NEW_MESSAGE").send({

const signer = provider.getSigner();

const contractABI =
'[{"inputs":[{"internalType":"string","name":"initMessage","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"string","name":"newMessage","type":"string"}],"name":"update","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"message","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"}]';
const contractAddress = "0xD65AF91Bbb4334711A598dFD293596E6dc2d8313#code";
const contract = new ethers.Contract(contractAddress, contractABI, signer);
const contractABI = [
{ inputs: [{ internalType: "string", name: "initMessage", type: "string" }], stateMutability: "nonpayable", type: "constructor" },
{ inputs: [], name: "message", outputs: [{ internalType: "string", name: "", type: "string" }], stateMutability: "view", type: "function" },
{
inputs: [{ internalType: "string", name: "newMessage", type: "string" }],
name: "update",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
];
const contractAddress = "0x04cA407965D60C2B39d892a1DFB1d1d9C30d0334";
const contract = new ethers.Contract(contractAddress, JSON.parse(JSON.stringify(contractABI)), signer);

// Send transaction to smart contract to update message
const tx = await contract.update("NEW_MESSAGE");
Expand Down
3 changes: 2 additions & 1 deletion src/common/docs/_smart-contract-solidity.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ In this example, we'll be demonstrating how to use Web3Auth with web3.js or ethe
World contract allows anyone to read and write a message to it.

```tsx
pragma solidity ^0.8.18;
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;

contract HelloWorld {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```javascript
import OpenloginAdapter from "@web3auth/openlogin-adapter";
import { OpenloginAdapter } from "@web3auth/openlogin-adapter";

const openloginAdapter = new OpenloginAdapter({
adapterSettings: {
Expand Down
2 changes: 1 addition & 1 deletion src/common/sdk/pnp/web/_openlogin-whitelabel-example.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```javascript
import OpenloginAdapter from "@web3auth/openlogin-adapter";
import { OpenloginAdapter } from "@web3auth/openlogin-adapter";

const openloginAdapter = new OpenloginAdapter({
adapterSettings: {
Expand Down

0 comments on commit 8beba59

Please sign in to comment.