Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions content/evm/evm-foundry.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ $ forge test
If tests pass, deploy the contract to the Sei chain with the following command:

```bash copy
$ forge create --rpc-url $SEI_NODE_URI --mnemonic $MNEMONIC src/Counter.sol:Counter
$ forge create --rpc-url $SEI_NODE_URI --mnemonic $MNEMONIC src/Counter.sol:Counter --broadcast
```

Where `$SEI_NODE_URI` is the URI of the Sei node and `$MNEMONIC` is the mnemonic of the account that will deploy the contract. If you run local Sei node, the address will be `http://localhost:8545` , otherwise you could grab a `evm_rpc` url from the [registry](https://github.com/sei-protocol/chain-registry/blob/main/chains.json). If deployment is successful, you will get the EVM contract address in the output.
Expand Down Expand Up @@ -109,15 +109,21 @@ If command is successful, you will get the transaction hash and other info back.

Now let's call the `getCount` function again and this case it should return `1`.

## Calling contract from JS client
```bash copy
$ cast call $0X_CONTRACT_ADDRESS "getCount()(uint256)" --rpc-url $SEI_NODE_URI
```

> Foundry generates the ABI for the contract in the `out` folder. You can use this ABI to interact with the contract from other tools like `ethers.js` or `web3.js`.

## Calling contract using ethers.js

To call contract from frontend, you could use `ethers` like:
To call or query the contract from a frontend or a NodeJS script, you could use `ethers.js` like:

```tsx copy
import {ethers} from "ethers";
import { ethers } from 'ethers';

const privateKey = <Your Private Key>;
const evmRpcEndpoint = <Your Evm Rpc Endpoint>
const privateKey = YOUR_PRIVATE_KEY;
const evmRpcEndpoint = YOUR_EVM_RPC_ENDPOINT;
const provider = new ethers.JsonRpcProvider(evmRpcEndpoint);
const signer = new ethers.Wallet(privateKey, provider);

Expand Down Expand Up @@ -162,7 +168,7 @@ const abi = [
];

// Define the address of the deployed contract
const contractAddress = 0X_CONTRACT_ADDRESS;
const contractAddress = `0X_CONTRACT_ADDRESS`;

// Create a new instance of the ethers.js Contract object
const contract = new ethers.Contract(contractAddress, abi, signer);
Expand Down