Skip to content
Open
Show file tree
Hide file tree
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
48 changes: 30 additions & 18 deletions bridge/messaging-bridge/evm-to-n3.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,29 +122,41 @@ Once the result is transferred, it can be read on the EVM chain.
## Example Implementation (JavaScript)

```javascript
const { ethers } = require('ethers');
const {ethers} = require('ethers');

// Define the target contract address and the account address to check the balance for.
const neoTokenContractAddress = "0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5"; // Neo token address on N3
const targetAddress = "0xabcdefabcdefabcdefabcdefabcdefabcdefabcd"; // Address to check the balance for

function exampleFunc() {
// TBD: Serialize an N3 method call using Javascript
// Invoke the N3 MessageBridge contract's function serializeN3MethodCall() to get the bytes needed.
// const rawMessage = n3MessageBridge.serializeN3MethodCall(target, method, callFlags, args);
const rawMessage = "0x400428141418e358c565207768eae8d237241e85d3e9f1cb280573746f72652101024002210101210440a87c68";

const storeResult = true;
const sendingFee = ethers.parseEther("0.1");
await evmMessageBridge.connect(sender).sendExecutableMessage(rawMessage, storeResult, {value: sendingFee, maxFeePerGas, maxPriorityFeePerGas});

// Wait until the message arrives on N3...

// TBD: Execute message on N3 using Javascript
// Invoke the method executeMessage() on the MessageBridge contract on N3 using the assigned message nonce when the message was sent.

// TBD: Send the result back from N3 to EVM
// Invoke the method sendResultMessage() on the MessageBridge contract on N3 using the assigned message nonce when the message was sent initially.
async function exampleFunc() {
// Assume evmMessageBridge and n3MessageBridge are already instantiated contract objects

// Serialize an N3 method call using the N3 MessageBridge
const rawMessage = await n3MessageBridge.serializeCall(
neoTokenContractAddress, // Target contract (NEO token)
'balanceOf', // Method to call
15, // CallFlags.ALL - can be adjusted as needed
[targetAddress] // Arguments
);
// const rawMessage = "0x400428141418e358c565207768eae8d237241e85d3e9f1cb280573746f72652101024002210101210440a87c68"; // Example serialized message

const storeResult = true;
let sendingFee = ethers.parseEther("0.1");
const nonce = await evmMessageBridge.connect(evmSender)
.sendExecutableMessage(rawMessage, storeResult, {value: sendingFee, maxFeePerGas, maxPriorityFeePerGas});

// Wait until the message arrives on N3...

// Execute message on N3 using Javascript
await n3MessageBridge.executeMessage(nonce);

// Send the result back from N3 to EVM
sendingFee = await n3MessageBridge.sendingFee();
const params: SendResultMessageParams = {
nonce: nonce,
maxFee: sendingFee
};
await n3MessageBridge.sendResultMessage(params);
}
```

Expand Down
15 changes: 10 additions & 5 deletions bridge/messaging-bridge/n3-to-evm.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Once the result is transferred, it can be read on-chain on N3.
## Example Implementation (JavaScript)

```javascript
const { ethers } = require('ethers');
const {ethers} = require('ethers');

// Define the Neo token contract address on EVM and target address
const neoTokenContractAddress = "0xc28736dc83f4fd43d6fb832Fd93c3eE7bB26828f"; // Neo token address on Neo X Testnet
Expand All @@ -148,12 +148,17 @@ const erc20Interface = new ethers.Interface([
"function balanceOf(address account) view returns (uint256)"
]);

function exampleFunc() {
async function exampleFunc() {
const encodedMessage = getEncodedMessage("0xc28736dc83f4fd43d6fb832Fd93c3eE7bB26828f", "0xabcdefabcdefabcdefabcdefabcdefabcdefabcd");

// TBD: Send message on N3 using Javascript
// Invoke the method sendExecutableMessage on the MessageBridge contract on N3 using the encodedMessage bytes.
// const nonce = n3MessageBridge.sendExecutableMessage(messageBytes, true, sender, messageFee);
// Send message on N3 using Javascript
const sendingFee = await messageBridge.sendingFee();
const params: SendExecutableMessageParams = {
encodedMessage,
true, // storeResult
maxFee: sendingFee
};
await messageBridge.sendExecutableMessage(params)

// Wait until the message arrives on the EVM chain...

Expand Down