Skip to content

Instantly share code, notes, and snippets.

@svanas
Last active May 31, 2023 17:16
Show Gist options
  • Save svanas/e5d06317e37d4a095ea8d18b358e153f to your computer and use it in GitHub Desktop.
Save svanas/e5d06317e37d4a095ea8d18b358e153f to your computer and use it in GitHub Desktop.
Swap 100 USDC for WETH on Ethereum
const client: IWeb3 = TWeb3.Create(
web3.eth.infura.endpoint(web3.Ethereum, INFURA_PROJECT_ID).Value
);
web3.eth.balancer.v2.swap(
client,
owner,
TSwapKind.GivenIn,
'0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
'0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH
web3.utils.scale(100, 6), // 100 USDC
0, // limit
web3.Infinite, // deadline
procedure(rcpt: ITxReceipt; err: IError)
begin
if Assigned(err) then
// handle error gracefully
else
// your transaction got mined
end);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment