Note: Synthetix uses a proxy system. The ABI of the underlying Synthetix ProxyERC20 contract you need is Synthetix. Learn more about how proxies work by visiting the overview page.
const{SynthetixJs}=require('synthetix-js');constprivateKey='0x'+'1'.repeat(64);// don't actually put a private key in code obviously// parameters: default provider, default networkId, private key as a stringconstnetworkId=3;// ropsten, (use 1 for mainnet)constsigner=newSynthetixJs.signers.PrivateKey(null,networkId,privateKey);constsnxjs=newSynthetixJs({signer,networkId});(async()=>{try{// get debt owingconstdebt=awaitsnxjs.Synthetix.debtBalanceOf(signer.address,snxjs.utils.toUtf8Bytes32('sUSD'));// burn all debt owingconsttxn=awaitsnxjs.Synthetix.burnSynths(debt);console.log('hash is mining',txn.hash);// wait for miningawaittxn.wait();// fetch logs of transactionconst{logs}=awaitsigner.provider.getTransactionReceipt(txn.hash);// show themconsole.log(JSON.stringify(logs,null,'\t'));}catch(err){console.log('Error',err);}})();
constsynthetix=require('synthetix');// nodejsconstethers=require('ethers');// nodejs// or using ES modules:// import synthetix from 'synthetix';// import ethers from 'ethers';constnetwork='ropsten';constprovider=ethers.getDefaultProvider(network==='mainnet'?'homestead':network);const{address}=synthetix.getTarget({network,contract:'ProxyERC20'});const{abi}=synthetix.getSource({network,contract:'Synthetix'});constprivateKey='0x'+'1'.repeat(64);// don't actually put a private key in code obviouslyconstsigner=newethers.Wallet(privateKey).connect(provider);// see https://docs.ethers.io/ethers.js/html/api-contract.html#connecting-to-existing-contractsconstSynthetix=newethers.Contract(address,abi,signer);(async()=>{try{constdebt=awaitSynthetix.debtBalanceOf(signer.address,synthetix.toBytes32('sUSD'));// burn all debt owingconsttxn=awaitSynthetix.burnSynths(debt);// wait for miningawaittxn.wait();// fetch logs of transactionconst{logs}=awaitprovider.getTransactionReceipt(txn.hash);// displayconsole.log(JSON.stringify(logs,null,'\t'));}catch(err){console.log('Error',err);}})();
pragma solidity0.5.16;import"synthetix/contracts/interfaces/IAddressResolver.sol";import"synthetix/contracts/interfaces/ISynthetix.sol";contractMyContract{// This should be instantiated with our ReadProxyAddressResolver// it's a ReadProxy that won't change, so safe to code it here without a setter// see https://docs.synthetix.io/addresses for addresses in mainnet and testnetsIAddressResolverpublicsynthetixResolver;constructor(IAddressResolver_snxResolver)public{synthetixResolver=_snxResolver;}functionsynthetixBurn()external{ISynthetixsynthetix=synthetixResolver.getAddress("Synthetix");require(synthetix!=address(0),"Synthetix is missing from Synthetix resolver");uintdebt=synthetix.debtBalanceOf(msg.sender,"sUSD");// Burn for msg.sender = address(MyContract)synthetix.burnSynths(debt);}functionsynthetixBurnOnBehalf(addressuser)external{ISynthetixsynthetix=synthetixResolver.getAddress("Synthetix");require(synthetix!=address(0),"Synthetix is missing from Synthetix resolver");uintdebt=synthetix.debtBalanceOf(user,"sUSD");// Note: this will fail if `DelegateApprovals.approveBurnOnBehalf(address(MyContract))` has// not yet been invoked by the `user`synthetix.burnSynthsOnBehalf(user,debt);}}