Skip to content

flows-network/ethereum-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ethereum-example

Deploy this function on flows.network, and you will get a web service that using ethers to send transaction.

image

Deploy the ethereum-example

To install this ethereum-example, we will use flows.network, a serverless platform that makes deploying your own app quick and easy in just three steps.

Prerequisite

You will need a wallet private key. If you do not already have one, use Metamask to create it.

Fork this repo and write your own code

Fork this repo.

Deploy the code on flow.network

  1. Sign up for an account for deploying flows on flows.network. It's free.
  2. Click on the "Create a Flow" button to start deploying the web service.
  3. Authenticate the flows.network to access the ethereum-example repo you just forked.

image

  1. Click on the Advanced text and you will see more settings including branch and environment variables. In this example, we have one variable PRIVATE_KEY to fill in, which is the wallet private key. The default network is Arbitrum sepolia. If you want to change network, you can set RPC_NODE_URL and CHAIN_ID variable.

image

  1. Click the Deploy button to deploy your function.

Configure SaaS integrations

After that, the flows.network will direct you to configure the SaaS integration required by your flow. Here we can see: there is no SaaS needs to be connected since it's a lambda service. Just click the Check button to see your flow details.

image

Try this demo

After the flow function's status becomes ready, you will see a link under the Lambda Endpoint.

In the ethereum example, it implements three types of web3 service. You can use different paths of URLs to change services.

image

Sign-tx

You just provide basic information, sign-tx service can help you sign and send transactions.

Copy and paste the endpoint URL to your browser and add /sign-tx?address_to=0xf04c6a55F0fdc0A5490d83Be69A7A675912A5AB3&value=10000000000000000 to send 0.01 ETH to 0xf04c6a55F0fdc0A5490d83Be69A7A675912A5AB3. Then you can see the transaction hash.

image

If you want to send a transaction with a data parameter, you can add a new query parameter named data to send hex encode bytes.

PBM-pay

Before the demo, you can follow the README of pbm-pilot to create a hardhat project. Upload your ERC 20 token contract or stablecoin's token.sol to hardhat/contracts Finally copy ethereum-example.js to hardhat/script, then use npx hardhat run script/ethereum-example.js --network sepolia to run the script.

The script will do the following things.

  1. Deploy an ERC 20 token contract and PBM contract.
  2. Mint 1000000 token to userB.
  3. userB use pbm fund 1000 token to userC

After running the script, you need to set the PBM contract address to CONTRACT_ADDRESS in flows.network setting configuration and ensure the PRIVATE_KEY is userC. image

PBM-pay service will call the PBM contract pay function to transfer 10 tokens to someone.

Copy and paste the endpoint URL to your browser and add /pbm-pay?pay-to=0x70655c1c0D7Ef1273D17E5610a2079E7465F0FF6 to let PBM contract send 10 tokens to 0x70655c1c0D7Ef1273D17E5610a2079E7465F0FF6. Then you can see the transaction hash.
(Ensure the pay-to address has been added to the PBM contract whitelist)

image

Gen-key

Gen-key service will random generate an ethereum account. If you want to generate an account from mnemonic, you and add phrase to query parameter. Copy and paste the endpoint URL to your browser and add /gen-key. Then you can see the account address.

image

The Running log will show the address and the private key.

image

Get_pbm_balance

(Before using the service you need to provide CONTRACT_ADDRESS in flows.network setting configuration.)

Get_pbm_balance service will query an address balance in the pbm. You need to add address to the query parameter. Copy and paste the endpoint URL to your browser and add /get_pbm_balance?address=0x70655c1c0D7Ef1273D17E5610a2079E7465F0FF6. Then you can see the balance. image

Get_pbm_from_txs

(Before using the service you need to provide CONTRACT_ADDRESS in flows.network setting configuration.)

Get_pbm_from_txs will query a transaction of address that transfers tokens from PBM to another account. You need to add address to the query parameter. Copy and paste the endpoint URL to your browser and add /get_pbm_from_txs?address=0x70655c1c0D7Ef1273D17E5610a2079E7465F0FF6. Then you can see the transaction result.

image

Get_pbm_to_txs

(Before using the service you need to provide CONTRACT_ADDRESS in flows.network setting configuration.)

Get_pbm_to_txs will query a transaction of the address that receives PBM transfer token. You need to add address to the query parameter. Copy and paste the endpoint URL to your browser and add /get_pbm_to_txs?address=0x8091f38dd65bae3ceef0c9ea51780172c535f94e. Then you can see the transaction result.

image

Get_balance

Get_balance service will query an address balance. You need to add address to the query parameter. Copy and paste the endpoint URL to your browser and add /get_balance?address=0x8091f38dd65bae3ceef0c9ea51780172c535f94e. Then you can see the balance.

image

Get_txs

(This service needed another explorer API. It is implemented by CMT tracking and moralis, only supporting CyberMiles and some chains. If you do not use CyberMiles, you need to provide MORALIS_API_KEY in flows.network setting configuration.)

Get_txs service will query an address balance and send transaction. You need to add address to the query parameter. Copy and paste the endpoint URL to your browser and add /get_txs?address=0x70655c1c0D7Ef1273D17E5610a2079E7465F0FF6. Then you can see the balance and transaction.

image

Get_erc20_balance

(If you do not use CyberMiles, you need to provide MORALIS_API_KEY in flows.network setting configuration.)

Get_erc20_balance service will query all the token of the address. You need to add address to the query parameter. Copy and paste the endpoint URL to your browser and add /get_erc20_balance?address=0x70655c1c0D7Ef1273D17E5610a2079E7465F0FF6. Then you can see the token.

image

Get_erc20_from_txs

(If you do not use CyberMiles, you need to provide MORALIS_API_KEY in flows.network setting configuration.)

Get_erc20_from_txs will query a transaction of address that transfers erc20 tokens to another account. You need to add address to the query parameter. Copy and paste the endpoint URL to your browser and add /get_erc20_from_txs?address=0x70655c1c0D7Ef1273D17E5610a2079E7465F0FF6. Then you can see the transaction result.

image

Get_erc20_to_txes

(If you do not use CyberMiles, you need to provide MORALIS_API_KEY in flows.network setting configuration.)

Get_erc20_to_txs will query a transaction of the address that receives erc20 token. You need to add address to the query parameter. Copy and paste the endpoint URL to your browser and add /get_erc20_to_txs?address=0x8091f38dd65bae3ceef0c9ea51780172c535f94e. Then you can see the transaction result.

image

flows.network is still in its early stages. We would love to hear your feedback!

Others

To build locally, make sure you have intsalled Rust and added wasm32-wasi target.

cargo build target wasm32-wasi --release

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published