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
85 changes: 85 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,91 @@ For the SVM (Solana) contract, see https://github.com/wormholelabs-xyz/example-n

Deployments can be found at https://wormholelabs.notion.site/Executor-Addresses-Public-1f93029e88cb80df940eeb8867a01081

## Example Usage

First, build the contracts to generate the ABI:

```bash
forge build
```

Here's a basic example using viem to approve and transfer tokens:

```javascript
import { createWalletClient, createPublicClient, http, erc20Abi } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { sepolia } from "viem/chains";
import nttExecutorAbi from "./out/NttManagerWithExecutor.sol/NttManagerWithExecutor.json" assert { type: "json" };

const account = privateKeyToAccount("0x...");
const publicClient = createPublicClient({
chain: sepolia,
transport: http("https://your-rpc-url.com"),
});
const walletClient = createWalletClient({
account,
chain: sepolia,
transport: http("https://your-rpc-url.com"),
});

async function transferWithExecutor() {
// Contract addresses
const tokenAddress = "0x...";
const nttManagerAddress = "0x...";
const nttManagerWithExecutorAddress = "0x...";

// Transfer parameters
const amount = 1000000000000000n; // Amount to transfer
const recipientChain = 1; // Target chain ID
const recipientAddress = "0x..."; // 32-byte recipient address

// Get quote from executor service (implement based on your executor API)
const { signedQuote, estimatedCost } = await getExecutorQuote();

// Step 1: Approve tokens
await walletClient.writeContract({
address: tokenAddress,
abi: erc20Abi,
functionName: "approve",
args: [nttManagerWithExecutorAddress, amount],
});

// Step 2: Transfer with executor
const transferTx = await walletClient.writeContract({
address: nttManagerWithExecutorAddress,
abi: nttExecutorAbi.abi,
functionName: "transfer",
args: [
nttManagerAddress,
amount,
recipientChain,
recipientAddress,
recipientAddress, // refund address
"0x01000101", // encodedInstructions
{
value: estimatedCost,
refundAddress: account.address,
signedQuote: signedQuote,
instructions: "0x...", // relay instructions from executor
},
{
dbps: 0, // referrer fee
payee: account.address,
},
],
value: estimatedCost,
});

console.log("Transfer complete:", transferTx);
}

transferWithExecutor().catch(console.error);
```

**Notes**:

- For Solana transfers, convert recipient addresses from base58 to 32-byte hex format

⚠ **This software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied. See the License for the specific language governing permissions and limitations under the License.** Or plainly
spoken - this is a very complex piece of software which targets a bleeding-edge, experimental smart contract runtime.
Expand Down