Skip to content

Commit

Permalink
Merge pull request #904 from onflow/jord/doc-updates
Browse files Browse the repository at this point in the history
Fix several EVM on Flow doc examples
  • Loading branch information
Aliserag authored Sep 21, 2024
2 parents e66d239 + 1d4e43e commit 0c40a4f
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions docs/evm/cadence/interacting-with-coa.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ import "EVM"
access(all)
fun main(address: Address): EVM.EVMAddress {
// Get the desired Flow account holding the COA in storage
let account: = getAuthAccount<auth(Storage) &Account>(address)
let account = getAuthAccount<auth(Storage) &Account>(address)
// Borrow a reference to the COA from the storage location we saved it to
let coa = account.storage.borrow<&EVM.CadenceOwnedAccount>(
Expand Down Expand Up @@ -168,7 +168,7 @@ import "EVM"
access(all)
fun main(address: Address): EVM.Balance {
// Get the desired Flow account holding the COA in storage
let account: = getAuthAccount<auth(Storage) &Account>(address)
let account = getAuthAccount<auth(Storage) &Account>(address)
// Borrow a reference to the COA from the storage location we saved it to
let coa = account.storage.borrow<&EVM.CadenceOwnedAccount>(
Expand Down Expand Up @@ -217,9 +217,8 @@ transaction(amount: UFix64) {
prepare(signer: auth(BorrowValue) &Account) {
// Borrow the public capability to the COA from the desired account
// This script could be modified to deposit into any account with a `EVM.CadenceOwnedAccount` capability
self.coa = signer.capabilities.borrow<&EVM.CadenceOwnedAccount>(
from: /public/evm
) ?? panic("Could not borrow reference to the COA")
self.coa = signer.capabilities.borrow<&EVM.CadenceOwnedAccount>(/public/evm)
?? panic("Could not borrow reference to the COA")
// Withdraw the balance from the COA, we will use this later to deposit into the receiving account
let vaultRef = signer.storage.borrow<auth(FungibleToken.Withdraw) &FlowToken.Vault>(
Expand All @@ -230,7 +229,7 @@ transaction(amount: UFix64) {
execute {
// Deposit the withdrawn tokens into the COA
coa.deposit(from: <-self.sentVault)
self.coa.deposit(from: <-self.sentVault)
}
}
```
Expand Down Expand Up @@ -276,7 +275,7 @@ transaction(amount: UFix64) {
execute {
// Deposit the withdrawn tokens into the receiving vault
receiver.deposit(from: <-self.sentVault)
self.receiver.deposit(from: <-self.sentVault)
}
}
```
Expand All @@ -294,7 +293,7 @@ This transaction will use the signer's COA to call a contract method with the de
```cadence
import "EVM"
transaction(evmContractHex: String, signature: String, args: [AnyStruct], gasLimit: UInt64, value: UFix64) {
transaction(evmContractHex: String, signature: String, args: [AnyStruct], gasLimit: UInt64, flowValue: UFix64) {
let coa: auth(EVM.Call) &EVM.CadenceOwnedAccount
prepare(signer: auth(BorrowValue) &Account) {
Expand All @@ -314,11 +313,11 @@ transaction(evmContractHex: String, signature: String, args: [AnyStruct], gasLim
)
// Define the value as EVM.Balance struct
let value = EVM.Balance(attoflow: 0)
value.setFLOW(flow: value)
value.setFLOW(flow: flowValue)
// Call the contract at the given EVM address with the given data, gas limit, and value
// These values could be configured through the transaction arguments or other means
// however, for simplicity, we will hardcode them here
let result: EVM.Result = coa.call(
let result: EVM.Result = self.coa.call(
to: contractAddress,
data: calldata,
gasLimit: gasLimit,
Expand Down

0 comments on commit 0c40a4f

Please sign in to comment.