Deploy this function on flows.network, and you will get a web service that using ethers to send transaction.
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.
You will need a wallet private key. If you do not already have one, use Metamask to create it.
Fork this repo.
- Sign up for an account for deploying flows on flows.network. It's free.
- Click on the "Create a Flow" button to start deploying the web service.
- Authenticate the flows.network to access the
ethereum-example
repo you just forked.
- 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 setRPC_NODE_URL
andCHAIN_ID
variable.
- Click the Deploy button to deploy your function.
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.
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.
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.
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.
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.
- Deploy an ERC 20 token contract and PBM contract.
- Mint 1000000 token to userB.
- 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.
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)
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.
The Running log will show the address and the private key.
(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.
(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.
(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.
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.
(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.
(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.
(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.
(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.
flows.network is still in its early stages. We would love to hear your feedback!
To build locally, make sure you have intsalled Rust and added wasm32-wasi
target.
cargo build target wasm32-wasi --release